Guest User

Untitled

a guest
Dec 19th, 2015
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.36 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Domain name, username, and password from your Google Domains control panel
  4. MyGDomain=
  5. Username=
  6. Password=
  7. # WAN interface name
  8. WANInterface=
  9.  
  10. # Record current WAN IP address from the WAN network interface
  11. CurrWANIP=$(ip -o -4 addr show $WANInterface | awk -F '[ /]+' '{print $4}')
  12. # Record IP which your Google domain is currently resolving to
  13. GDNSIP=$(dig $MyGDomain +short)
  14.  
  15. # Check if current external IP address matches the address your Google domain resolves to
  16. if [ "$CurrWANIP" == "$GDNSIP" ]; then
  17.         # If the IP addresses match, your domain is up to date. Exit.
  18.         logger "Google Domains DDNS: WAN IP ($CurrWANIP) unchanged, no update necessary"
  19. else
  20.         # If the IP addresses do not match, send a POST request over HTTPS to the Google DDNS API to update the record
  21.         ipupdate=$(curl -s https://$Username:$Password@domains.google.com/nic/update?hostname=$MyGDomain&myip=$CurrWANIP)
  22.         # Check if the updated IP returned in the HTTP response matches the current external IP
  23.         if [ "$ipupdate" == "good $CurrWANIP" ]; then
  24.          # If IP addresses match, log and exit
  25.          logger "Google Domains DDNS: DNS updated to $CurrWANIP from $GDNSIP"
  26.         else
  27.          # If IP addresses do not match, log out output to stderr the HTTP response
  28.          logger -s "Google Domains DDNS: Error: $ipupdate"
  29.         fi
  30. fi
Advertisement
Add Comment
Please, Sign In to add comment