$crontab-e
and add this line
55 * * * * * elinks https://USERNAME:PASSWORD@updates.opendns.com/nic/update
that will update your ip at 55 minutes past every hour
WARNING - make sure you have elinks installed and get your openDNS password and username correct!
cut and paste the following into any text editor, and save as "opendns.py"
modify lines 7,8 and 9 as per comments.
#! /usr/bin/python
import time
#-- put your openDNS username and password in here.....
#-- get these correct, otherwise the script will hang.
#-- and specify a location to store the ip. script needs write access in this folder!
user="your_name"
passwd="your_password"
last_known_ipFile="/home/USER/last_known_ip.txt"
def main():
from urllib import urlopen
print "\n",time.ctime(),
print "running ip update script...checking current ip",
try:
f=urlopen("http://whatismyip.com/automation/n09230945.asp")
my_ip=f.read()
f.close()
print my_ip
try:
f=open(last_known_ip,"r")
old_ip=f.read()
f.close()
except:
print "last known ip file '%s' not found, forcing update"%last_known_ipFile
old_ip=""
if my_ip==old_ip:
print "no update needed, OpenDNS have correct ip."
else:
print "updating OpenDNS account",
try:
print urlopen("https://%s:%s@updates.opendns.com/nic/update"%(user,passwd)).read()
#-- if we've got this far, the update is successful.... write this ip to file.
f=open(last_known_ipFile,"w")
f.write(my_ip)
f.close()
except:
print "error updating"
except:
print "unable to fetch your current ip - is your network up?\nclosing."
if __name__ == "__main__":
main()
..............make that script executable
$chmod +x opendns.py
..............then set up a cron job
$crontab-e
..............enter
EITHER of the following (ammended as necessary...)
55 * * * * * /home/DIRECTORY/opendns.py
OR
55 * * * * * /home/DIRECTORY/opendns.py>>opendnslog.txt
and the script will run at 55minutes past every hour, creating a log "opendnslog.txt" if you went for the second version.
(this file will need to be trimmed occasionally).
If you improve the python script, or if you have any problems, give me a shout at rowinggolfer AT hotmail.com