· 6 years ago · Dec 06, 2019, 12:28 PM
1#!/bin/bash
2
3# This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection.
4# Special thanks to mfox for his ps script
5# https://github.com/markafox/GoDaddy_Powershell_DDNS
6#
7# First go to GoDaddy developer site to create a developer account and get your key and secret
8#
9# https://developer.godaddy.com/getstarted
10# Be aware that there are 2 types of key and secret - one for the test server and one for the production server
11# Get a key and secret for the production server
12#
13#Update the first 4 variables with your information
14
15domain="" # your domain
16name="" # name of A record to update
17key="" # key for godaddy developer API
18secret="" # secret for godaddy developer API
19
20headers="Authorization: sso-key $key:$secret"
21
22# echo $headers
23
24result=$(curl -s -X GET -H "$headers" \
25 "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
26
27dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
28# echo "dnsIp:" $dnsIp
29
30# Get public ip address there are several websites that can do this.
31ret=$(curl -s GET "http://ipinfo.io/json")
32currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
33# echo "currentIp:" $currentIp
34
35 if [ $dnsIp != $currentIp ];
36 then
37# echo "Ips are not equal"
38 request='{"data":"'$currentIp'","ttl":3600}'
39# echo $request
40 nresult=$(curl -i -s -X PUT \
41 -H "$headers" \
42 -H "Content-Type: application/json" \
43 -d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
44# echo $nresult
45fi