Created
January 27, 2013 15:59
-
-
Save ergatea/4648976 to your computer and use it in GitHub Desktop.
This file contains 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/python | |
# Set up a new A record in Cloudflare, add the details of it along with your account details below | |
# Make sure this script runs on startup (or whenever you get a new IP...) | |
# | |
# @author Aaron Rice <[email protected]> | |
import urllib | |
import json | |
import sys | |
try: | |
new_ip = urllib.urlopen("http://ip.sisca.info/").read() | |
except: | |
print "Error getting IP" | |
sys.exit() | |
# Put your Cloudflare settings here. | |
# The host must be an A record that already exists in cloudflare | |
data = { | |
"a" : "DIUP", | |
"tkn" : "", | |
"u" : "", | |
"ip" : new_ip.strip(), | |
"z" : "", | |
"hosts" : "", | |
} | |
try: | |
dns_response = json.loads(urllib.urlopen("https://www.cloudflare.com/api_json.html", urllib.urlencode(data)).read()) | |
if dns_response[u'result'] == "success": | |
print "IP updated to " + new_ip, | |
else: | |
print "Error Setting IP" | |
except: | |
print "Error with cloudflare API" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment