Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save blackknight36/b5e42faa77202e1906492fc2a2f8a64b to your computer and use it in GitHub Desktop.

Select an option

Save blackknight36/b5e42faa77202e1906492fc2a2f8a64b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
import requests
def main():
update_record('example.com', 'home', 'ID')
def update_record(zone, name, id):
newip = requests.get('https://icanhazip.com').text.rstrip()
baseurl = 'https://api.digitalocean.com'
apiurl = "/v2/domains/%s/records/%s" %(zone, id)
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'}
payload = {'name': name, 'id': id, 'type': 'A', 'data': newip}
r = requests.put(baseurl+apiurl, headers=headers, data=json.dumps(payload))
print json.dumps(json.loads(r.text), indent=2)
print ""
print "Record updated. New ip: %s" %newip
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment