Print Shortlink

Subverting’s manual IP updating for free accounts with Python is popular provider of static to dynamic host names. Their service allows those of us with dynamic IPs to have a static host name by use of a client that periodically updates the ip address the host name points to. Recently, sites like dyndns and no-ip have started requiring their free users to log in and perform a manual update of their hosts through the provider’s website. Failing to do so at regular intervals will result in a suspension of the domain. Knowing that I would almost certainly forget to update my hosts, I wrote a quick and dirty python script to take care of that for me. I have my linux box run this once a week as a cronjob and it has run successfully for the last few months. Note that if any of the URLs change the script will need to be altered.

My script uses mechanize to handle the url stuff. Here is the easy way to install it in Ubuntu if you don’t already have it:

  1. sudo apt-get install python-setuptools python-dev build-essential
  2. sudo easy_install mechanize

Next, log into your no-ip account and perform and open the details of each host in your account. You will see a host ID listed in the url. Replace the <first>, <second> and , <third> values in the script below with your IDs. Also insert your username and password for the account. Dump the updated code into a file, add read protection to prevent other users from looking at your account details and run the script. Your hosts should update with their existing ip addresses – you might want to double check in the web interface.

I recommend executing this script from a cronjob so you don’t have to worry about it later.


import sys, mechanize, cookielib, re, os

# Variables

login_site = ‘’
host_ids = [<first>,<second>,<third>]
update_site = ‘’
logout_url = ‘’
username = ‘<username>’
password = ‘<password>’

# Initialize browser and cookie handling

br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [(‘User-agent’, ‘Firefox’)]

# Open the login page and apply credentials

print “Connecting to”,login_site
br.form[‘username’] = username
br.form[‘password’] = password
print “Logging in…”
print ‘Currently on page:’, br.title()

for host_id in host_ids:
print ‘Updating host ID:’, host_id
print update_site+str(host_id)
print ‘Currently on page:’, br.title()

# Logout
print ‘Done, logging out.’

Leave a Reply

You must be logged in to post a comment.