Skip to content

Commit b9226e1

Browse files
authored
Create GoDaddyDNS.sh
1 parent 6e92904 commit b9226e1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

GoDaddyDNS.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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
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+
15+
domain="$1" #from command line
16+
name="@" # name of A record to update
17+
key="--your key" # key for godaddy developer API
18+
secret="--your secret--" # secret for godaddy developer API
19+
20+
headers="Authorization: sso-key $key:$secret"
21+
22+
# echo $headers
23+
24+
result=$(curl -s -X GET -H "$headers" \
25+
"https://api.godaddy.com/v1/domains/$domain/records/A/$name")
26+
27+
dnsIp=$(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.
31+
ret=$(curl -s GET "http://ipinfo.io/json")
32+
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
33+
# echo "currentIp:" $currentIp
34+
# if [ "$dnsIpa" = "$currentIp" ];
35+
if [ "$dnsIp" != "$currentIp" ];
36+
then
37+
# echo "Ips are not equal"
38+
request='[{"data":"'$currentIp'","ttl":600}]'
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
45+
fi

0 commit comments

Comments
 (0)