Skip to content

Instantly share code, notes, and snippets.

@DAP-DarkneSS
Created March 25, 2012 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DAP-DarkneSS/2193180 to your computer and use it in GitHub Desktop.
Save DAP-DarkneSS/2193180 to your computer and use it in GitHub Desktop.
Tool to update DNS at freedns.afraid.org using curl&dig [v.2.0]
#!/bin/bash
HLPARG=--help
KDEARG=--kde
HOSTSARG=--hosts
DOM=$1
HASH=$2
HOSTS=/etc/hosts
if [ -n "`echo $@ | grep -o -- $HLPARG`" ]
then
OUT="Tool to update DNS at freedns.afraid.org.\n\n\
Usage: dnsupdate.sh [DOMAIN] [UPDATE HASH] [OPTION]\n\n\
Options:\n\t--help\t\tprint this help.\n\
\t--hosts\t\tmodify domen entry in /etc/hosts, the entry must exist.\n\
\t--kde\t\toutput to KDE system notifications.\n\n\
Originally written by Adam Dean.\n\
See it at http://freedns.afraid.org/scripts/update.sh.txt\n\
Mail bug reports and suggestions to <dap.darkness at gmail dot com>."
else
IPREG="`dig @8.8.8.8 $DOM | egrep -v "^$|;" | awk '{ print $5 }'`"
IPCUR="`curl -s http://checkip.dyndns.org | grep -o '[0-9.]*'`"
if [ "$IPCUR" != "$IPREG" ]
then
OUT="`curl -s "http://freedns.afraid.org/dynamic/update.php?"$HASH`"
if [ -n "`echo $@ | grep -o -- $HOSTSARG`" ]
then
cp $HOSTS $HOSTS.bak
sed "s/`grep $DOM $HOSTS | awk '{ print $1 }'`/$IPCUR/g" $HOSTS.bak > $HOSTS
fi
else
OUT="Address "$IPCUR" has not changed."
fi
fi
if [ -n "`echo $@ | grep -o -- $KDEARG`" ]
then
kdialog --title "DNS update" --passivepopup "$OUT"
else
echo -e "DNS update:\n""$OUT"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment