-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwanIPcheck
executable file
·74 lines (60 loc) · 1.79 KB
/
wanIPcheck
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
#!/bin/bash
force=false
while getopts :f opt; do
case "$opt" in
f)
force=true
;;
esac
done
#Create necessary files, set variables
dir=~/".wanip"
[ -d "$dir" ] || mkdir "$dir"
lastIP="${dir}/lastIP.log"
[ -f "$lastIP" ] || touch "$lastIP"
dnsConf="${dir}/ddns.conf"
[ -f "$dnsConf" ] || exit 1
emailAddr="[email protected]"
dnsServer="dynamicdns.park-your-domain.com"
oldIP=$(cat "$lastIP")
newIP=$(~/bin/wanip)
#If IP changed from log...
if [[ "$newIP" == "$oldIP" ]] && [[ $force != true ]]; then
echo "$(date): WAN IP remains unchanged."
else
echo "$(date): WAN IP changed to: $newIP"
echo "$newIP" > "$lastIP"
#Email out WAN IP update notice
mutt -e "set content_type=text/html" -s "WAN IP Change: $newIP" -- "$emailAddr" <<EOF
<!DOCTYPE html>
<html>
<head>
<title>WAN IP Change</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div><h1>WAN IP Change</h1></div>
<div>The web server IP has changed!</div>
<div>the new IP address is:</div>
<div>$newIP</div>
<div></div>
<div>The web server: <a href="http://$newIP/">http://$newIP/</a></div>
</body>
</html>
EOF
#Update DNS records
while IFS=',' read -r -a line -u 3; do
host="${line[0]}"
login="${line[1]}"
password="${line[2]}"
echo "Updating IP for:"
echo "Host: $host"
echo "Domain: $login"
#echo "GET REQUEST: ${dnsServer}/update?host=${host}&domain=${login}&password=${password}&ip=${newIP}"
wget -O - "${dnsServer}/update?host=${host}&domain=${login}&password=${password}&ip=${newIP}" 2>/dev/null | sed 's|<|\n<|g'
echo ""
echo ""
done 3<"$dnsConf"
fi
exit 0