-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspdnsupdater.sh
114 lines (81 loc) · 1.71 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
#!/bin/bash
# load last IP
LASTIP=0.0.0.0
if [ -f /tmp/lastip ];then
echo "import lastip"
source /tmp/lastip
echo "last ip was $LASTIP"
fi
#get current ip
IP=$(curl -s http://checkip4.spdyn.de/)
echo "current IP is $IP"
#check ip and last check
if [ "$IP" = "$LASTIP" ];then
if [ "$LASTCHECK" -le "$(( $(date +%s) - 10800 ))" ];then
echo "force ip update"
else
echo "no ip change"
exit
fi
fi
#update string
updateip(){
RETURNCODE=$(curl -s --user $1:$2 "https://update.spdyn.de/nic/update?hostname=$1&myip=$IP&pass=$2")
# eval return code
case $RETURNCODE in
nochg*)
echo "update done... IP was up2date"
;;
good*)
echo "update done... IP changed to $IP"
;;
abuse*)
>&2 echo "update failed: abuse error"
exit
;;
badauth*)
>&2 echo "update failed: wrong user or password"
exit
;;
numhost*)
>&2 echo "update failed: you try to update more as 20 hosts"
exit
;;
notfqdn*)
>&2 echo "update failed: host is not a FQDN"
exit
;;
!yours*)
>&2 echo "update failed: host is not assigned to your account"
exit
;;
fatal*)
>&2 echo "update failed: host is disabled"
exit
;;
nohost*)
>&2 echo "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 "LASTCHECK=$(date +%s)" >> /tmp/lastip
exit