-
Notifications
You must be signed in to change notification settings - Fork 64
/
ddns_godaddy.sh
76 lines (65 loc) · 1.84 KB
/
ddns_godaddy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#
# Bash script to update your godaddy dns record to your current public ip address (dynamic dns).
#
Usage(){
while read -r line; do
printf "%b\n" "$line"
done <<-EOF
\r#OPTIONS:
\r -i, --ip - Your Public IP Address.
\r -d, --domain - Your Domain Name (example.com).
\r -t, --type - DNS Record Type (default: A).
\r -n, --name - Subdomain Name (mysub) without domain name.
\r -k, --key - Godaddy Key (here: https://developer.godaddy.com/getstarted).
\r -s, --secret - Godaddy Secret.
\r -h, --help - Displays The Help And Exit.
\r
EOF
exit
}
# you can set default values here #
IP="$(curl -sk ipinfo.io/ip)"
DOMAIN="example.com"
TYPE="A"
NAME="mysub"
KEY=""
SEC=""
###################################
while [ -n "$1" ]; do
case $1 in
-i|--ip)
IP="$2"
shift ;;
-d|--domain)
DOMAIN="$2"
shift ;;
-t|--type)
TYPE="$2"
shift ;;
-n|--name)
NAME="$2"
shift ;;
-k|--key)
KEY="$2"
shift ;;
-s|--secret)
SEC="$2"
shift ;;
-h|--help)
Usage ;;
*)
echo "[-] Unknown Option: $1"
Usage ;;
esac
shift
done
DATA="[{\"data\": \"${IP}\", \"ttl\": 600}]"
HEADERS="Authorization: sso-key ${KEY}:${SEC}"
DNS=$(curl -s -XGET -H "$HEADERS" "https://api.godaddy.com/v1/domains/$DOMAIN/records/$TYPE/$NAME" | jq -r '.[].data')
[[ ${IP} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "[!] Check Your Internet Connection and Try Again!"; exit 1; }
[[ ${IP} == ${DNS} ]] && { echo "[!] Same IP, No Need To Update!"; exit 0; }
echo "New IP: ${IP}"
echo "[+] Updating DNS Record...."
curl -sk -XPUT -H "Content-Type: application/json" -H "Accept: application/json" -H "${HEADERS}" -d "${DATA}" https://api.godaddy.com/v1/domains/${DOMAIN}/records/${TYPE}/${NAME}
echo "[+] Done!"