Hacker Public Radio - shownotes on OpenDNS Episode

How to use an openDNS account if your ISP gives you a Dynamic IP

Firstly, make sure you have informed openDNS that you have a "dynamic ip".
There is a checkbox on their site.

Windows/Mac users install the software available from OpenDNS.



For Linux users, try one of the following methods.
Method 1 - Manual.
Periodically point your browser at the following link to update your ip.
https://USERNAME:PASSWORD@updates.opendns.com/nic/update
Method 2 - Automate the above with a command-line browser and cron in a console
$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!
Method 3 - My python Script.
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
page created 25 june 2008