forked from schnello/spdnsupdater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspdnsupdater.sh
117 lines (95 loc) · 2.18 KB
/
spdnsupdater.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
# load last IP
LASTIP=0.0.0.0
LASTIP6=0:0:0:0:0:0:0:0
if [ -f /tmp/lastip ]; then
echo "import lastip"
source /tmp/lastip
echo "last ip was $LASTIP"
fi
if [ -f /tmp/lastip6 ]; then
echo "import lastip6"
source /tmp/lastip6
echo "last ipv6 was $LASTIP6"
fi
#get current ip
IP=$(curl -s http://checkip4.spdyn.de/)
echo "current IPv4 is $IP"
IP6=$(curl -s http://checkip6.spdyn.de/)
#IP6=$(ip -6 addr show eth0 | grep inet6 | awk -F '[ \t]+|/' '{print $3}' | grep -v ^::1 | head -n 1)
echo "current IPv6 is $IP6"
#check if ipv4 and ipv6 are the same
if [ "$IP" = "$LASTIP" ] && [ "$IP6" = "$LASTIP6" ]; then
echo "no ip change"
exit
else
echo "force ip update"
fi
#update string
updateip() {
echo "Updating IPv4"
RETURNCODE=$(curl -s --user $1:$2 "https://update.spdyn.de/nic/update?hostname=$1&myip=$IP&pass=$2")
evalResult $RETURNCODE
echo "Updating IPv6"
RETURNCODE=$(curl -s --user $1:$2 "https://update.spdyn.de/nic/update?hostname=$1&myip=$IP6&pass=$2")
evalResult $RETURNCODE
}
evalResult() {
# eval return code
case $1 in
nochg*)
echo "update done... IP was up-to-date"
;;
good*)
echo "update done... IP changed"
;;
abuse*)
echo >&2 "update failed: abuse error"
exit
;;
badauth*)
echo >&2 "update failed: wrong user or password"
exit
;;
numhost*)
echo >&2 "update failed: you try to update more as 20 hosts"
exit
;;
notfqdn*)
echo >&2 "update failed: host is not a FQDN"
exit
;;
!yours*)
echo >&2 "update failed: host is not assigned to your account"
exit
;;
fatal*)
echo >&2 "update failed: host is disabled"
exit
;;
nohost*)
echo >&2 "update failed: host not available or deleted"
exit
;;
esac
}
# load domains and passwords from spdnsupdater.conf
if [ -f ~/.spdnsupdater.conf ]; then
echo "import config from ~/.spdnsupdater.conf "
source ~/.spdnsupdater.conf
else
echo "conf file \"$HOME/.spdnsupdater.conf\" not found"
exit
fi
# calc end for sequence
e=$(($(echo ${DOMAIN[*]} | wc -w) - 1))
#perform update
for ((i = 0; i <= $e; i++)); do
echo " "
echo "Update domain ${DOMAIN[$i]}"
updateip ${DOMAIN[$i]} ${PASSWORD[$i]}
echo " "
done
echo "LASTIP=$IP" >/tmp/lastip
echo "LASTIP6=$IP6" >/tmp/lastip6
exit