Skip to content

Instantly share code, notes, and snippets.

@OrcaXS
Created July 27, 2016 09:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save OrcaXS/27d00c5a6f7e4a9e34fa0e49e6a1e27e to your computer and use it in GitHub Desktop.
Save OrcaXS/27d00c5a6f7e4a9e34fa0e49e6a1e27e to your computer and use it in GitHub Desktop.
Google Dynamic DNS update script for Tomato firmware
#!/bin/sh
set -u
#set -x
U=username
P=password
H=hostname
IP="$(ip -o addr show ppp0 | awk '/inet / {print $4}')"
DIGIP="$(dig +short $H)"
PROXY=http://127.0.0.1:8118
# args: username password hostname
# Note: you might need to install curl from entware, since curl/libcurl from Tomato firmware might not support https.
google_dns_update() {
CMD=$(/opt/bin/curl -x $PROXY -s "https://$1:$2@domains.google.com/nic/update?hostname=$3&myip=$4")
logger "google-ddns-updated: $CMD"
echo "$CMD"
}
#sleep 30
echo "Interface IP is ${IP}, Query from DNS is ${DIGIP}"
if [ "$DIGIP" != "$IP" ]; then
google_dns_update $U $P $H $IP
else
echo "IPs are same, ddns update is not necessary"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment