Skip to content

Instantly share code, notes, and snippets.

@johnweldon
Created March 4, 2018 05:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnweldon/7feab4bd2eb48060900948bbc21fe456 to your computer and use it in GitHub Desktop.
Save johnweldon/7feab4bd2eb48060900948bbc21fe456 to your computer and use it in GitHub Desktop.
bash script to update dynamic dns ip address on google domains from a Zyxel C3000Z modem
#!/usr/bin/env bash
#
# Update Google Domains Dynamic DNS from Zyxel C3000Z modem information.
# Tested on a Centurylink issued modem, YMMV
#
# See https://support.google.com/domains/answer/6147083?hl=en for
# Google Domains help and credentials information
#
MODEM_BASE_URL="${MODEM_BASE_URL:-http://192.168.0.1}"
LOGINURL="$MODEM_BASE_URL/login.cgi"
STATUSURL="$MODEM_BASE_URL/modemstatus_connectionstatus.html"
# Create tempfile for cookies, and clean up on exit
export COOKIEFILE="$(mktemp)"
trap "rm -f ${COOKIEFILE}" EXIT
USER="${USERNAME:-admin}"
PASS="${PASSWORD:-fakepassword}"
# Login
curl --cookie-jar "$COOKIEFILE" -d "admin_username=$USER" -d "admin_password=$PASS" -XPOST "$LOGINURL" -o /dev/null
# Status
STATUSLINE="$(
curl --cookie "$COOKIEFILE" "$STATUSURL" | \
sed -e '/var allStatus/s/^var allStatus = "\(.*\)".*$/\1/p;d' | \
sed -e 's/||/\t/g'
)"
# Parse
IFS='\t' read -ra VARS <<< "$STATUSLINE"
IPv4="${VARS[9]}"
IPv6="${VARS[10]}"
echo "IPv4: $IPv4"
echo "IPv6: $IPv6"
USER="${GD_USERNAME:-fakeusrname}"
PASS="${GD_PASSWORD:-fakepssword}"
DYNHOST="${DYNHOST:-dyn.example.com}"
IPADDR="${IPv4}"
# Check
EXISTING="$(dig +short $DYNHOST)"
[ "$EXISTING" == "$IPv4" ] && echo "up-to-date" && exit
# Optionally update
curl -u "$USER:$PASS" "https://domains.google.com/nic/update?hostname=${DYNHOST}&myip=${IPADDR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment