adventures in ddns part 3
In the last part, I introduced the nsupdate command. Unfortunately, nsupdate takes a lot of information, so to cut down on time, I created a python wrapper.
Before I wrote this, I took a look at, both, Newtrino and dnspython, but neither were exactly what I was looking for. Newtrino comes with a Python class that wraps around nsupdate, but was too complicated for what I wanted. dnspython is a very robust DNS class for Python, but I could not get it to work cleanly with different types of DNS records and DDNS. I ended up combining ideas from both programs and writing my own.
A normal nsupdate conversation looks like this:
$ nsupdate -y MYKEY:blargh
> server 127.0.0.1
> zone example.com
> update add host1.example.com 36000 IN A 192.168.1.10
> send
> ^D
My ddns.py script looks something like this:
ddns.py add host1.example.com A 192.168.1.10
You can see it's a lot shorter.
Basically, it follows the same syntax as nsupdate, but cuts out the repetitive server, zone, and send commands and gets rid of the timeout and IN portions of the update command.
You can get the code here: ddns.py
In order to use this script, you'll need to the .key file generated in Part 1. Copy and paste the path to that file to line 26 of the ddns.py script.
You'll also need the dnspython package for the dns.resolver class.
That should do it!
