Skip to content

Instantly share code, notes, and snippets.

@andrew-nuwber
Last active May 21, 2025 18:11

Revisions

  1. andrew-nuwber revised this gist Jan 17, 2020. No changes.
  2. andrew-nuwber created this gist Jan 17, 2020.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    1. Login to Namecheap Account
    1. Get JSON from https://ap.www.namecheap.com/Domains/dns/GetAdvancedDnsInfo?fillTransferInfo=false&domainName=YOURDOMAINNAME.com
    1. Save it to file
    1. `python main.py data.json`
    42 changes: 42 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    # Originally by Judotens Budiarto (https://github.com/judotens)
    # See: https://gist.github.com/judotens/151341f04b37ffeb5b59

    def parse_dns_info(dns_info):
    records = dns_info['Result']['CustomHostRecords']['Records']
    items = []
    for record in records:
    host = str(record['Host'])
    if record['RecordType'] == 1: tipe = 'A'
    if record['RecordType'] == 2: tipe = 'CNAME'
    if record['RecordType'] == 3: tipe = 'MX'
    if record['RecordType'] == 5: tipe = 'TXT'

    value = str(record['Data'])
    ttl = str(record['Ttl'])
    priority = str(record['Priority'])
    active = record['IsActive']
    if not active: continue
    new_value = value
    if tipe == 'MX': new_value = "%s %s" % (str(priority), str(value))
    if tipe == 'TXT': new_value = "\"%s\"" % (str(value))

    items.append([host,ttl,"IN", tipe, new_value])

    return items

    if __name__ == "__main__":
    import sys
    import json

    file_name = sys.argv[1]

    try:
    file = open(file_name, 'r')
    except IOError:
    print("File not accessible")

    dns_info = json.loads(file.read());

    zones = parse_dns_info(dns_info)
    for zone in zones:
    print "\t".join(zone)