Skip to content

Instantly share code, notes, and snippets.

@da-h
Last active March 13, 2019 18:50
Show Gist options
  • Save da-h/19b93103f2631b92eacc9e384a8aad0c to your computer and use it in GitHub Desktop.
Save da-h/19b93103f2631b92eacc9e384a8aad0c to your computer and use it in GitHub Desktop.
DynDNS with Curl and dig.
#!/bin/bash
DNS="
firstdns.com
seconddns.com
"
SERVER=dyndns.xxx/nic/update
USERNAME=xxx
PASSWORD=xxx
# arguments:
# update_dyndns.sh version=4 or 6
if [[ $# -eq 0 ]] ; then
echo "No version specified"
exit
elif [[ $1 -ne 4 && $1 -ne 6 ]] ; then
echo "IP-Version can be only 4 or 6"
exit
fi
# init
UPDATE=false
VER=$1
IP=$(dig -$VER TXT +short o-o.myaddr.l.google.com @ns1.google.com)
IPFILE="/tmp/current_ip"$VER
echo IPv$VER: $IP
# check for update
if [ ! -f $IPFILE ] ; then
UPDATE=true
else
IPOLD=$(cat $IPFILE)
if [ "$IPOLD" != "$IP" ] ; then
UPDATE=true;
fi
fi
# no need for update
if [ $UPDATE == "false" ] ; then
echo "No UPDATE needed"
exit
fi
# do update
echo $IP > $IPFILE
for dns in $DNS; do
echo UPDATING IPv$VER: $dns;
curl -D - --user $USERNAME:$PASSWORD https://$SERVER?hostname=$dns
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment