Skip to content

Instantly share code, notes, and snippets.

@tx0dev
Created February 22, 2013 06:30
Show Gist options
  • Save tx0dev/5011200 to your computer and use it in GitHub Desktop.
Save tx0dev/5011200 to your computer and use it in GitHub Desktop.
Updater for Hurricane Electric for their Dynamic dns service. IPv6 updates are NOT enable at the moment.
#!/bin/bash
# HOSTS
HOSTS="example.com foo.example.com"
# HOSTS PASSWORD
# Because I'm lazy, it needs to be the same for all hosts
HOST_KEY="YOUR_PASSWORD"
# Get Current IPs
current4=`curl -4 -s http://checkip.dns.he.net | grep -o -E '([0-9]{1,3}\.){3}[0-9]{1,3}'`
#current6=`curl -6 -s http://checkip.dns.he.net | grep -o -E '([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}'`
for h in $HOSTS; do
dns4=`host -t A $h | grep -o -E '([0-9]{1,3}\.){3}[0-9]{1,3}'`
if [ "$current4" != "$dns4" ]; then
if [ ! -z $update ]; then
update=x;
else
update="x$update";
fi
r4=$(curl -s -4 "http://$h:$HOST_KEY@dyn.dns.he.net/nic/update?hostname=$h")
if ! [[ "$r4" =~ "good" || "$r4" =~ "nochg" ]]; then
logger -p local0.err -t HE-DDNS "DNS update failed for $h: $r4"
fi
fi
# For IPv6
# dns6=`host -t AAAA $h | grep -o -E '([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}'`
# if [ "$current6" != "$dns6" ]; then
# if [ ! -z $update ]; then
# update=x;
# else
# update="x$update";
# fi
# r6=$(curl -s -6 "http://$h:$HOST_KEY@dyn.dns.he.net/nic/update?hostname=$h")
# if ! [[ "$r6" =~ "good" || "$r6" =~ "nochg" ]]; then
# logger -p local0.err -t HE-DDNS "DNS update failed for $h: $r6"
# fi
# fi
done
if [ -z "$update" ]; then
WC=`echo $HOSTS | wc -w`
logger -p local0.notice -t HE-DDNS "No DNS update needed ($WC hosts)"
else
WC=`echo $update | wc -c`
logger -p local0.info -t HE-DDNS "DNS changed for $WC entries to $current4"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment