Check VPN connection
In category Routers .
IPsec:
For indication if the IPsec tunnel is established you can use command "stroke" (/usr/libexec/ipsec/stroke). The script below is very simple example which checks every 5 seconds whether IPsec tunnel is established. If it is then USER LED is lights.
Simple example script (ipsec_stat.sh):
#!/bin/sh num=1 # number of IPSec [1,2,3,4] while true do /usr/libexec/ipsec/stroke status | awk "/ipsec$num/" | grep INSTALLED sts=$? if [ "$sts" = "0" ]; then led on else led off fi sleep 5 done
Copy the script ipsec_stat.sh to e.g. root folder and finelly execute it from Startup Script, see below.
Startup Script:
#!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here. sh /root/ipsec_stat.sh &
You can also use a technique described in this arcticle How can I create my own script?
OpenVPN:
The OpenVPN tunnel is a bit problematic because there is not exist "management" port in the routers so it is not possible to indicate that VPN connection is established. Nevertheless you can use the OpenVPN Up/Down script for indicaton that the OpenVPN is started.
Create two very simple scripts.
ledon.sh:
#!/bin/sh led on
ledoff.sh:
#!/bin/sh led off
Then copy these scripts to e.g. root folder and finaly add line below to Extra Option of OpenVPN configuration on web GUI.
--script-security 2 --up /root/ledon.sh --down /root/ledoff.sh
NOTE:
The checking of OpenVPN tunnel is useable only for indicate if VPN tunnel is running. It doesn't indicate that the connection is established!