#!/usr/bin/perl -w # #adsl.pl #name:check adsl connect #author: fengyong #2006-12-20 use strict; use vars qw ($fping @ips); my $fping = "/usr/local/sbin/fping"; my @ips=("ip_address1","ip_address2","ip_address3"); #this is test ip,uncomment it when the script is ok. #my @ips=("1.1.1.1","1.2.4.5","2.1.1.1"); sub check_ip { my $ip=shift; my $ret=`$fping -t 10 $ip`; chomp $ret; if ($ret =~/$ip is alive/){ return 1; }else{ return 0; } } sub chk_adsl { my $counter=0; foreach my $ip(@ips){ if (&check_ip($ip)){ $counter++; } } if ($counter > 2){ return 0; }else{ return 1; } } sub reconnect { system ( "/usr/bin/killall ppp"); system ("/usr/sbin/ppp -ddial -nat adsl"); } if (&chk_adsl){ &reconnect; }