Created
August 15, 2021 02:54
-
-
Save edguy3/df6d4f297b86e32f32d73f2598775eeb to your computer and use it in GitHub Desktop.
Update goDaddy record with current IP using API (like dynamic DNS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection. | |
# Special thanks to mfox for his ps script | |
# https://github.com/markafox/GoDaddy_Powershell_DDNS | |
# and r0b0t at | |
# https://www.godaddy.com/community/Managing-Domains/Dynamic-DNS-Updates/td-p/7862/page/2 | |
# | |
# 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 | |
# | |
# read https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplaceTypeName | |
# | |
#Update the first 4 variables with your information | |
domain="example.com" # your domain | |
name="myHost" # name of A record to update | |
key="" # key for godaddy developer API | |
secret="" # secret for godaddy developer API | |
headers="Authorization: sso-key $key:$secret" | |
result=$(curl -s -X GET -H "$headers" | |
"https://api.godaddy.com/v1/domains/$domain/records/A/$name") | |
dnsIp=$(echo $result| jq -r '.[0].data') | |
ttl=$(echo $result| jq -r '.[0].ttl') | |
# Get public ip address there are several websites that can do this. | |
ret=$(curl -s GET "http://ipinfo.io/json") | |
currentIp=$(echo $ret | jq -r '.ip') | |
echo " Public IP:" $currentIp | |
if [ "$dnsIp" != $currentIp ] || [ "$1" = "-f" ]; | |
then | |
echo "Updating Ip to $currentIp" | |
request=$(echo "$result" | jq -r --arg newIP $currentIp '.[0].data = $newIP | .') | |
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