Wednesday, 16 January 2013

update-dnsomatic and dig

I have been using update-dnsomatic on my home server for some years now and it has worked well. Yesterday, I noticed that an update had 'worked' but the DNS entry had not propagated for some reason or other.

As a result of this, I have written a quick script that compares my public IP with a dig query which sends me a DM via twitter to let me know when they are different.

Files below: digip, cihip (Can I Haz IP), dmpr4wn

You need dnsutils (for dig) and a working copy of TTYtter for this to work.

Simply run digip every half hour or so and any discrepancy will be notified via twitter direct message.

Code:

#!/bin/sh
# digip
DIG=$(dig prawn.mooo.com | grep ^prawn.mooo.com | awk '{ print $5 }')
CIH=$(cihip)

if [ "$CIH" == "" ]
then
        echo "Public IP address is blank. Exiting."
        exit 1
fi

if [ "$DIG" == "" ]
then
        echo "DNS IP address is blank. Exiting."
        exit 2
fi


if [ "$DIG" != "$CIH" ]
then
       echo "Dig IP $DIG does not match public IP $CIH"
dmpr4wn "Dig IP $DIG does not match public IP $CIH"
else
echo "Dig IP $DIG matches public IP $CIH ok"
fi

###########################


#!/bin/sh
#cihip Can I haz IP
wget -qO - http://myip.dnsomatic.com/
echo

##########################

#!/bin/sh
#dmpr4wn
TWEET="/dm pr4wn"
ttytter -status="$TWEET $1" -hold

1 comment:

Lina Hennessey said...

I am so glad this internet thing works and your article really helped bridesmaid dresses 2013, top wedding dresses, prom dresses store me. Might take you up on that home advice you.