#!/usr/bin/perl $version='$Id: conncheck.pl,v 1.1 2006/02/23 12:36:28 torh Exp torh $'; # # (c) th+usenet@bogus.net # # checks connectivity to a specified IP address # # $|=1; # where "date" and "ping" live # $ENV{'PATH'}="/bin:/usr/bin:/usr/sbin:/sbin"; use Getopt::Long; my($ping,$date,$target); undef($DOWN); undef($DEBUG); GetOptions("h","v","d", "t=s" => \$target, "f=s" => \$logfile); if($opt_d) { $DEBUG=1; } # no target specified? default: if(!$target) { # (i wrote this for NTL, so for me, the closest UBR) # make sure ICMP echo/echo-reply isn't blocked by you (or them) # to this address $target="80.3.65.133"; print "No target defined, using default: $target\n"; } if($opt_v) { print $version,"\n"; exit(1); } if($opt_h) { print $version,"\n"; print "usage: conntest [-h|-d|] [-t ] [-f ]","\n"; print " -h : this","\n"; print " -v : version string","\n"; print " -f : logfile","\n"; print " -d : switch on debugging information","\n"; print " -t : target to ping (default: $target)","\n"; exit(1); } if($logfile) { open(LOG,">$logfile"); } while(1) { $ping=`ping -c 5 $target`; if($ping =~ /\s+(\d+)% packet loss/) { $pc=$1; } $date=`date`; chop($date); if($pc == 100) { if(!$DOWN) { print "$target unreachable at $date","\n"; } $DOWN=1; } if($pc < 100) { if($DOWN) { print "$target reachable at $date","\n"; } $DOWN=0; } sleep(1); }