#!/usr/bin/perl -w # # A really simple multihosts ping utility aimed at tracking connectivity # status. Run as root or suided root. # # Rel. 0.1.2 use Net::Ping; my @hosts = qw( www.qwests.com www.internet2.edu www.ipservices.att.com www.xo.com www.rnp.br www.verizonbusiness.com global.mci.com www.fastweb.it www.google.it ); my $pinger = Net::Ping->new('icmp'); $pinger->hires(1); # Report milliseconds in response times print "Testing connectivity: pinging " . scalar(@hosts) . " hosts as requested.\n\n"; foreach my $host (@hosts) { my($ret,$time,$ip) = $pinger->ping($host, 2); # two seconds of timeout unless($ret) { # the host isn't reachable, so we need to manually define the variables # we are going to use $time = 0; $ip = 'xxxxx'; } printf("%-3s %-5f: %-25s [%-15s]\n", ($ret ? "up" : "dwn"), $time , $host, $ip); } print "\n"; $pinger->close(); exit 0;