From 9c56d2d8fbaeba5aa3aa90bf3b4980090224d2f2 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 26 Dec 2017 17:27:56 +0000 Subject: [PATCH] Create GoDaddyScript --- bin/GoDaddyScript | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 bin/GoDaddyScript diff --git a/bin/GoDaddyScript b/bin/GoDaddyScript new file mode 100644 index 00000000..9da732a8 --- /dev/null +++ b/bin/GoDaddyScript @@ -0,0 +1,46 @@ +#!/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 +# +# 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 "Current record: $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":1800}' + 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