Created
January 4, 2017 13:52
-
-
Save blackknight36/b5e42faa77202e1906492fc2a2f8a64b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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