#!/usr/bin/perl -w use strict; use Net::Ping; my $NB_PING=5; my $host="dslreports.com"; my( $ok, $nok, $total_time)=(0,0,0); # use the icmp protocol to emulate the unix ping # note that this implies that the script should be # run as root (or suid root) my $p = Net::Ping->new( "icmp"); $p->hires(); # needs Time::Hires foreach (1..$NB_PING) { my ($ret, $duration, $ip) = $p->ping($host, 3); # 3 is the time out in sec if( $ret) { $ok++; $total_time+= $duration * 1000; } else { $nok++; } } $p->close(); # we don't want division by 0 errors do we? my $average= $ok ? int($total_time / $ok) : 0; my $lost= int ( ($nok / ( $ok + $nok)) * 100); print "$lost%\n$average\n0\n0\n";