-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathipcheck
executable file
·40 lines (28 loc) · 1.28 KB
/
ipcheck
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
#!/bin/vbash
source /opt/vyatta/etc/functions/script-template
IP=$(ip addr show dev eth4 | awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/); ip = substr($0,RSTART,RLENGTH); print ip}' | sed '/^$/d')
IP2=$(configure; show vpn l2tp remote-access outside-address | cut -f3 -d ' ';)
IP3=$(curl -m 10 ifconfig.co)
if [ -z "$IP3" ]
then
logger -p local0.notice [IPERROR] "ifconfig.co isn't responding. is the whole internet down??"
break
fi
if [ $IP = $IP2 ] && [ $IP = $IP3 ]
then
logger -p local0.notice [IPCOOL] "Config had $IP2 while the web matched with $IP3"
exit
else
logger -p local0.notice [HIPJINX] "Config had $IP2 while the web returned $IP3"
logger -p local0.notice [HIPJINX] "Attempting to correct."
logger -p local0.notice [HIPJINX] "Setting VPN to listen on $IP3"
set vpn l2tp remote-access outside-address $IP3
logger -p local0.notice [HIPJINX] "Setting forwarding for RasPi"
set nat destination rule 20 destination address $IP3
logger -p local0.notice [HIPJINX] "Setting firewall group network"
NEW_NET=$(ip addr show dev eth4 | awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/[0-9]+/); sub(/[0-9]+\//, "0/"); ip = substr($0,RSTART,RLENGTH); print ip}' | sed '/^$/d')
set firewall group network-group NET-WAN network $NEW_NET
commit && save
exit
fi
exit