Created
March 25, 2012 12:05
-
-
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]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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