mikelieman

BASH script to update Google Domains DDNS

Mar 2nd, 2021 (edited)
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. #!/usr/bin/bash
  2.  
  3. DDNS_HOSTNAME=example.com
  4.  
  5. SERVER=domains.google.com
  6. GOOGLE_USER=
  7. GOOGLE_PASS=
  8.  
  9. TEST_HOST=example.com
  10.  
  11. CURL_EXE="/usr/bin/curl -4 --user-agent curl -s -get"
  12.  
  13. CURRENT_IP=$(${CURL_EXE} https://${SERVER}/checkip)
  14. DNS_IP=$(/usr/bin/host ${TEST_HOST} | grep "has address" | awk '{print $4}')
  15. VPN_UP=$(ip link ls wgpia0 2>&1)
  16.  
  17. echo -n "Expected IPv4 addr: ${DNS_IP}, Current IPv4 addr: ${CURRENT_IP} - "
  18.  
  19. if [ "$DNS_IP" != "$CURRENT_IP" ]; then
  20.  
  21.     echo "IPv4 Addresses DO NOT match."
  22.  
  23.     if [ "${VPN_UP}" == "Device \"wgpia0\" does not exist." ]; then
  24.  
  25.         echo -n "VPN is not up.  Attempting to update ${SERVER}... "
  26.         RETVAL=$(${CURL_EXE} https://${GOOGLE_USER}:${GOOGLE_PASS}@${SERVER}/nic/update?hostname=${DDNS_HOSTNAME})
  27.         echo -n "${RETVAL} - "
  28.         xmessage -display :0.0 "Your WAN IP address has changed and is now ${CURRENT_IP}."
  29.  
  30.     else
  31.         echo -n "VPN is up.  Skipping - "
  32.     fi # vpn_up
  33.  
  34. else
  35.     echo -n "IPv4 addresses match - "
  36. fi # dns != current
  37.  
  38. echo "Done."
  39.  
Add Comment
Please, Sign In to add comment