#!/usr/bin/perl $vpn = ""; # VPN-server IP $gw = ""; # Default gw IP $ping_host = ""; # Host to ping (to check the connection) $login = ""; # VPN login sub inetup { print "Inet starting .. "; system("/usr/sbin/pptp ${vpn} name ${login}"); print "Sleeping...\n"; sleep(5); print "Route del...\n"; `/sbin/route del default`; print "Route add...\n"; `/sbin/route add default dev ppp0`; print "done\n"; } sub inetdown { print "Inet shutdown .. "; `/usr/bin/killall pppd`; sleep(10); `/usr/bin/killall -9 pppd`; sleep(5); `/usr/bin/killall -9 pptp`; `/sbin/route del default`; `/sbin/route add default gw ${gw}`; print "done\n"; } $res_ = `/sbin/ifconfig | grep ppp0`; # There is ppp0 iface if ($res_) { print "ppp0 is up. Let's check ppp1: "; @res__ = `/sbin/ifconfig | grep ppp`; if ($#res__>0) { print "it is up!!!\n"; inetdown; } else { print "it is missing. OK\n"; } } # There is no ppp0 iface else { print "Inet is down !\n"; inetdown; inetup; } print "Ping check: "; @res___ = `/bin/ping ${ping_host} -c 10 | grep "64.*bytes"`; if ($#res___ < 1) { print "failed\n"; inetdown; inetup; } else { print "OK\n"; } exit 0;