Print Shortlink

Subverting no-ip.org’s manual IP updating for free accounts with Python

No-ip.org 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.

#!/usr/bin/python

import sys, mechanize, cookielib, re, os

# Variables

login_site = ‘https://www.noip.com/login/’
host_ids = [<first>,<second>,<third>]
update_site = ‘https://www.noip.com/members/dns/host.php?host_id=’
logout_url = ‘https://www.noip.com/login/?logout=1’
username = ‘<username>’
password = ‘<password>’

# Initialize browser and cookie handling

br = mechanize.Browser()
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
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.open(login_site)
br.select_form(nr=0)
br.form[‘username’] = username
br.form[‘password’] = password
print “Logging in…”
br.submit()
print ‘Currently on page:’, br.title()

for host_id in host_ids:
print ‘Updating host ID:’, host_id
print update_site+str(host_id)
br.open(update_site+str(host_id))
br.select_form(nr=0)
br.submit()
print ‘Currently on page:’, br.title()

# Logout
print ‘Done, logging out.’
br.open(logout_url)

Leave a Reply

You must be logged in to post a comment.