Skip to content

Instantly share code, notes, and snippets.

@dstufft
Created April 1, 2011 01:48
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 dstufft/897610 to your computer and use it in GitHub Desktop.
Save dstufft/897610 to your computer and use it in GitHub Desktop.
Dynamic DNS w/ Linode DNS
#!/usr/bin/env python
import urllib
import json
import sys
LINODE_API_URL = 'https://api.linode.com/'
LINODE_API_KEY = '' # Add in your Linode API Key
TARGET_DOMAIN = 'example.com' # Replace with domain name
TARGET_RECORD = 'home' # Replace with sub domain
def do_api(action, **kwargs):
kwargs['api_key'] = LINODE_API_KEY
kwargs['api_action'] = action
params = urllib.urlencode(kwargs)
f = urllib.urlopen('?'.join([LINODE_API_URL, params]))
json_resp = json.load(f)
return json_resp
domains = do_api('domain.list')['DATA']
domain_id = None
for domain in domains:
if domain['DOMAIN'] == TARGET_DOMAIN:
domain_id = domain['DOMAINID']
break
if domain_id is None:
sys.exit('%s is not found in list' % TARGET_DOMAIN)
records = [
x for x in do_api('domain.resource.list', DomainID=domain_id)['DATA']
if x['NAME'] == TARGET_RECORD and x['TYPE'].upper() in ('A',)
]
for record in records:
print do_api('domain.resource.update',
DomainID=record['DOMAINID'], ResourceID=record['RESOURCEID'],
Target='[remote_addr]')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment