Skip to content

Instantly share code, notes, and snippets.

@carlosmarin
Created August 25, 2014 18:41
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 carlosmarin/2d6009bc67e86c44cd66 to your computer and use it in GitHub Desktop.
Save carlosmarin/2d6009bc67e86c44cd66 to your computer and use it in GitHub Desktop.
duckdns.org
#!/bin/sh
## Sample run:
## chmod 700 ~/Dropbox/apps/_running_/duck.sh
## crontab -e
## */5 * * * * ~/Dropbox/apps/_running_/duck.sh ingcma utun1 >/dev/null 2>&1
NAME=$1
IFACE=$2
TOKEN=<ENTER-TOKEN>
#TOKEN=$3
LOG=$HOME/.duckdns.log
usage(){
echo "Usage: $0 domain-hostname interface"
exit 1
}
( test -z "$NAME" || test -z "$IFACE" ) && usage
#Linux: IP=$(/sbin/ifconfig ${IFACE} | grep 'inet addr' | sed -e 's/:/ /' | awk '{print $3}')
#Mac OS X
IP=$(/sbin/ifconfig ${IFACE} | grep 'inet' | tail -n 1 | sed -e 's/:/ /' | awk '{print $2}')
test -z "$IP"
if [[ $? -eq 0 ]]; then
echo "Unable to get valid IP, quitting.";
exit 0
fi
FILE="/tmp/duckdns.${IFACE}.${NAME}"
if [ -e $FILE ]; then
read LASTIP < $FILE
if [ "$IP" = "$LASTIP" ]; then
echo "IP: $IP hasn't changed, early exit.";
exit 0
fi
fi
echo $IP > $FILE
echo "Setting ${NAME} to '${IP}' (from iface ${IFACE})"
echo url="https://www.duckdns.org/update?domains=${NAME}&token=${TOKEN}&ip=${IP}" | curl -o $LOG -k -K -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment