Posted on : 08-10-2008 | By : Japh
I’ve setup my home network with a domain and wanted to be able to access my home server, from my office, on a subdomain.
However, as is probably the case for most of you, I have a dynamic IP address assigned to my router when it connects to the Internet through my ISP. So I decided I’d have to setup my own dynamic DNS process!
First things first, it was necessary to create the subdomain I wanted and point it to my home router’s external IP address, and also to change the configuration on my router to forward all traffic on port 80 to my home server’s internal IP address.
Next I needed a small script, PHP in this case, on my web server that simply outputs a tiny bit of XML with the current IP address of the visitor.
'; ?> <!--[CDATA[<?php echo $_SERVER['REMOTE_ADDR']-->]]> |
Then I wrote a small Python script that retrieves the IP address from the PHP script, and calls WebFaction’s server API to update the DNS record. This script runs on a crontab every hour, so if my IP address changes, I only have to wait an hour at most for an update.
#!/usr/bin/env python import urllib from xml.dom import minidom import xmlrpclib dyndomain = 'homeserver.example.com' ip_url = urllib.urlopen('http://www.example.com/ip.php') ip_dom = minidom.parse(ip_url) ip_string = ip_dom.toxml() ip_address = ip_dom.getElementsByTagName("ip")[0].childNodes[0].data print ip_address server = xmlrpclib.ServerProxy('https://api.webfaction.com/') session_id, account = server.login('username', 'password') server.delete_dns_override(session_id, dyndomain) server.create_dns_override(session_id, dyndomain, ip_address, '', '', '', '') |
Next I may add logging, so I can see when my IP address changes, but that’s optional really.
Note: Also, if someone can recommend a really good code-highlighter plugin for WordPress, I’d be very grateful!
No related posts.





Hey Japh,
I’m using http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/ on lukedingle.com –> it uses the open source syntax highlighting package.
Hope it helps –> it definitely supports python.
Awesome! Thanks for that, I’ll try it out
Got a new post on the way soon too!