Chris Dzombak

sharing preview • dzombak.com

Very Simple Dynamic DNS Client

Very Simple Dynamic DNS Client

I have recently found a need for a Dynamic DNS client for my desktop. This, based on a script from Jeremy Zawodny, is what I’ve come up with:

#!/bin/bash
T_USER=TWITTER_USER
T_PASS=TWITTER_PASSWORD
T_URL=http://twitter.com/statuses/update.xml

cd $HOME

LAST_IP=`cat .last_ip`
IP=`curl -s -o - http://ip.cdzombak.net/index.php`

if [ $LAST_IP != $IP ]; then
    echo "Twitter @$T_USER..."
    curl -s -o /dev/null -u $T_USER:$T_PASS -d status="$IP" $T_URL
    echo "FreeDNS..."
    curl -s http://freedns.afraid.org/dynamic/update.php?FREEDNS_UPDATE_KEY
    echo "$IP" > .last_ip
    echo "Updated FreeDNS and @$T_USER to $IP"
fi

This is, of course, a bash script - meaning it is for *nix systems. It’s supposed to be run via a cron job (mine is set to run every 5 minutes). The script is very self-explanatory.

Right now, it updates FreeDNS and a Twitter account with my latest IP.

One note: if you use this, make sure that ~/.last_ip is not empty, even the first time you run the script. This will cause the script to fail on line 12 - bash ends up trying to run something like if [ != 67.186.45.67 ], which is obviously not correct.