K
Kevin Joseph
I am trying to write a Perl script which provides more detailed
information than the built in ping command. The built in command only
states <10ms, but I would like more details than that (as in Linux).
I wrote the following code (I have Perl v5.8.4 from ActiveState) which
works fine provided I comment the for loop with the sleep statement.
If I invoke it multiple times from the command line, I get 1-2ms on a
LAN which is ok.
The moment I uncomment the for loop, the first iteration works fine,
subsequent show only 0ms (almost as if its caching it.) Any ideas as
to what I am doing wrong ?
Thanks,
Kevin.
use Net:ing ;
use Time::HiRes qw(gettimeofday);
#for ($i=0 ; $i < 5 ; $i++ )
#{
$hostname=some_host ;
$p = Net:ing->new(icmp) ;
$p->hires() ;
($ret, $duration, $ip) = $p->ping($hostname,5) ;
($sec, $usec) = gettimeofday ;
$time = scalar(localtime($sec)) ;
printf("$time $hostname [ip: $ip] is alive : time : %.5f ms)\n",
1000*$duration)
if $ret ;
$p->close() ;
#sleep(1) ;
#}
information than the built in ping command. The built in command only
states <10ms, but I would like more details than that (as in Linux).
I wrote the following code (I have Perl v5.8.4 from ActiveState) which
works fine provided I comment the for loop with the sleep statement.
If I invoke it multiple times from the command line, I get 1-2ms on a
LAN which is ok.
The moment I uncomment the for loop, the first iteration works fine,
subsequent show only 0ms (almost as if its caching it.) Any ideas as
to what I am doing wrong ?
Thanks,
Kevin.
use Net:ing ;
use Time::HiRes qw(gettimeofday);
#for ($i=0 ; $i < 5 ; $i++ )
#{
$hostname=some_host ;
$p = Net:ing->new(icmp) ;
$p->hires() ;
($ret, $duration, $ip) = $p->ping($hostname,5) ;
($sec, $usec) = gettimeofday ;
$time = scalar(localtime($sec)) ;
printf("$time $hostname [ip: $ip] is alive : time : %.5f ms)\n",
1000*$duration)
if $ret ;
$p->close() ;
#sleep(1) ;
#}