Skip to content

Instantly share code, notes, and snippets.

@philhagen
Created June 3, 2013 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philhagen/5698359 to your computer and use it in GitHub Desktop.
Save philhagen/5698359 to your computer and use it in GitHub Desktop.
convert ALIAS records for all of your DNSimple domains to A records, including a TXT record to identify which domains were converted. The TXT record will allow automated reversal at a later date. The actual add/delete functions are commented here to allow you to run in "safe mode" first.
#!/usr/bin/python
from dnsimple import DNSimple
import socket
dns = DNSimple(email='foo@bar.com', api_token='your_token_here')
domains = dns.domains()
for domain in domains:
dname = domain['domain']['name']
print 'checking %s' % (dname)
records = dns.records(dname)
for record in records:
rtype = record['record']['record_type']
if rtype == 'ALIAS':
print '%s has ALIAS record' % (dname)
rid = record['record']['id']
aliastarget = record['record']['content']
targetip = socket.getaddrinfo(aliastarget, None)[0][4][0]
newrecord = { 'record_type': 'A', 'name': '', 'content': targetip }
placeholder = { 'record_type': 'TXT', 'name': 'backout', 'content': 'yes' }
print ' create A record: %s => %s' % (dname, targetip)
# dns.add_record(dname, newrecord)
print ' delete ALIAS record for %s' % (dname)
# dns.delete_record(dname, rid)
print ' create TXT record for later reversal of this change'
# dns.add_record(dname, placeholder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment