KD90

GoDaddy IP Address updater

Jun 6th, 2020
1,180
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. mydomain="<DOMAIN>"
  3. gdapikey="<Key>:<Secret>"
  4. myip=$(curl -s "https://api.ipify.org")
  5. ttl=3600
  6.  
  7. # "A" Record DNS names into array
  8. mapfile -t HostnameArray < <(curl -s -X GET -H "Authorization: sso-key ${gdapikey}" "https://api.godaddy.com/v1/domains/${mydomain}/records/A/" | grep -Po '(?<="name":")(.*?)(?=",)' | grep -v @)
  9.  
  10.  
  11. # "A" Record IP data into array
  12. mapfile -t IPArray < <(curl -s -X GET -H "Authorization: sso-key ${gdapikey}" "https://api.godaddy.com/v1/domains/${mydomain}/records/A/" | grep -Po '(?<="data":")(.*?)(?=",)' | grep -v @)
  13.  
  14. # For each IP entry check if IP is different, if it is, change all A records to new IP
  15. for gdip in "${IPArray[@]}";
  16. do
  17.     if  [ "${gdip}" != "$myip" -a "$myip" != "" ] ; then
  18.          echo "IP has changed!! Updating on GoDaddy"
  19.      
  20.          for currHost in "${HostnameArray[@]}"; do
  21.               echo Updating DNS for host name "${currHost}.${mydomain}. Changed IP from ${gdip} to ${myip}"
  22.        
  23.           curl -s -X PUT "https://api.godaddy.com/v1/domains/${mydomain}/records/A/${currHost}" -H "Authorization: sso-key ${gdapikey}" -H "Content-Type: application/json" -d "[{\"data\": \"${myip}\",\"ttl\":${ttl}}]"
  24.         done
  25. fi
  26. done
RAW Paste Data