Created
June 4, 2013 12:19
-
-
Save telekineticyeti/5705499 to your computer and use it in GitHub Desktop.
Python script to update your FreeDNS account with your new IP
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/python | |
# This script is an adaption of Jeremy Blythe's script (http://jeremyblythe.blogspot.co.uk/2012/05/python-freedns-client-on-raspberry-pi.html) | |
# It will update FreeDNS using multiple keys if you have "Link updates of the same IP together" Disabled. | |
import urllib2 | |
import os.path | |
FREEDNS_URL = 'http://freedns.afraid.org/dynamic/update.php?' | |
OLDIP_FILE = '/var/lib/misc/oldip' | |
USER_KEYS = ["", "", ""] | |
def updatedns(ip): | |
for key in USER_KEYS: | |
print urllib2.urlopen(FREEDNS_URL+key).read().strip() | |
f = open(OLDIP_FILE, 'w') | |
f.write(ip) | |
f.close() | |
newip = urllib2.urlopen("http://ip.dnsexit.com/").read().strip() | |
if not os.path.exists(OLDIP_FILE): | |
updatedns(newip) | |
else: | |
f = open(OLDIP_FILE, 'r') | |
oldip = f.read() | |
f.close() | |
if oldip != newip: | |
updatedns(newip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment