-
Notifications
You must be signed in to change notification settings - Fork 1
/
inwx-dns-updater.sh
executable file
·59 lines (54 loc) · 1.29 KB
/
inwx-dns-updater.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
#!/usr/bin/env bash
configfile="nsupdate.conf"
xmlfile="nsupdatedata.xml"
site="http://www.myip.ch"
while getopts :c: o
do
case $o in
c)
configfile=$OPTARG
;;
\?)
echo "ERROR: invalid option -$OPTARG." >&2
exit 1
;;
:)
echo "ERROR: option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if [ ! -f $configfile ]
then
echo "ERROR: config file '$configfile' not found." >&2
exit 1
fi
source $configfile
ns_ip=$(dig +short $hostname @ns.inwx.de 2>/dev/null)
if [ $? -ne 0 ]
then
echo "ERROR: could not retrieve DNS entry for ${hostname} from ns.inwx.de." >&2
exit 1
fi
wan_ip=$(curl -sf ${site} | grep -Po '(\d+\.){3}\d+')
if [ $? -ne 0 ]
then
echo "ERROR: could not retrieve current WAN address from ${site}." >&2
exit 1
fi
date=$(date "+%F %T")
if [ ! "${ns_ip}" == "${wan_ip}" ]
then
elements=${#entity_id[@]}
for (( i=0;i<$elements;i++))
do
curl -sfo /dev/null -d "$(cat ${xmlfile} | sed "s/%user%/${username}/g;s/%pass%/${password}/g;s/%ns_ent_id%/${entity_id[${i}]}/g;s/%wan_ip%/${wan_ip}/g")" https://api.domrobot.com/xmlrpc/
done
retcode=$?
if [ $retcode -ne 0 ]
then
echo "ERROR: failed to call xmlrpc API, curl return code: ${retcode}." >&2
else
echo "${date} – ${hostname} → ${wan_ip}"
fi
fi