Lost-Whisper

Yet another whisper lost.

webFaction - Dynamic DNS

So…  This is mainly just for me (so I can keep it somewhere), but here’s a dynamic DNS script for use at webFaction.

I like to carry around my computer, and my computers like to talk to each other (seriously)…  The only problem is that the IP addresses of the computers change throughout the day.

The easiest solution was to use DynamicDNS.  There’s probably several other ways to do this, and you can probably use some free service with an easy to install script, but if I have a host that supports it, why not use it?

So this is just a modification of the script originally post on the forums.  I tweaked it so the settings are at the top (to make it somewhat easy to modify), and so it can update multiple domains (because one of the computers is setup to send stuff to the older domain, but I bought a new shorter and cooler one)…  The last ip file is also hidden in Unix/Linux.

So here’s the script:

[python] #!/usr/bin/env python import urllib2 import xmlrpclib import os

Settings wfUser = ‘webfaction-user’ wfPass = ‘webfaction-pass’

wfDomain = [‘domain.one.com’, ‘domain.two.com’]

currentip = urllib2.urlopen(‘http://whatismyip.org’).read()

if not os.path.isfile(‘.lastip’): f = open(‘.lastip’, ‘w’) f.close()

with open(‘.lastip’, ‘r’) as f: lastip = f.read()

if lastip != currentip: server = xmlrpclib.ServerProxy(‘https://api.webfaction.com/’) session_id, account = server.login(wfUser, wfPass) for subDomain in wfDomain: server.delete_dns_override(session_id, subDomain) server.create_dns_override(session_id, subDomain, currentip, ”, ”, ”, ”) with open(‘.lastip’, ‘w’) as f: f.write(currentip) print(‘IP updated to %s’ % currentip) else: print(‘IP not updated’) [/python]

Chmod the file “chmod +x updateIP.py”

Add it to your crontab, I have:

0,30 * * * * /Users/scripts/updateIP.py >> /dev/null 2>&1

This runs the script every 30 minutes and redirects any output to null. Every 30 minutes is probably a bit of overkill (since I think the TTL is about an hour, and I’m not too experienced in the matters of DNS), you can probably run it once an hour or so.

So this let’s my computers talk to each other. They steal and store files on each other. There’s some other minor things as well that are cool.

It also allows me (and others) to SSH in without having to remember numbers and do some cool stuff, like compiling homework on a machine more powerful than our laptops.