Skip to content

Instantly share code, notes, and snippets.

@goedecke
Created January 2, 2018 15:31
Show Gist options
  • Save goedecke/96d1c1c49840475c3a6bec55796dc2cb to your computer and use it in GitHub Desktop.
Save goedecke/96d1c1c49840475c3a6bec55796dc2cb to your computer and use it in GitHub Desktop.
#!/bin/bash
# First go to GoDaddy developer site to create a developer account and get your key and secret
#
# https://developer.godaddy.com/getstarted
# Be aware that there are 2 types of key and secret - one for the test server and one for the production server
# Get a key and secret for the production server
#
#Update the first 4 variables with your information
domain="" # your domain
name="" # name of A record to update
key="" # key for godaddy developer API
secret="" # secret for godaddy developer API
headers="Authorization: sso-key $key:$secret"
# echo $headers
result=$(curl -s -X GET -H "$headers" \
"https://api.godaddy.com/v1/domains/$domain/records/A/$name")
#echo "Result" $result
dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
#echo "dnsIp:" $dnsIp
# Get public ip address there are several websites that can do this.
ret=$(curl -s GET "http://ipinfo.io/json")
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
#echo "currentIp:" $currentIp
if [ $dnsIp != $currentIp ];
then
# echo "Ips are not equal"
request='{"data":"'$currentIp'","ttl":3600}'
# echo $request
nresult=$(curl -i -s -X PUT \
-H "$headers" \
-H "Content-Type: application/json" \
-d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
# echo $nresult
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment