Win2k - Ping - improved.

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::ping ;
use Time::HiRes qw(gettimeofday);

#for ($i=0 ; $i < 5 ; $i++ )
#{
$hostname=some_host ;
$p = Net::ping->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) ;
#}
 
A

A. Sinan Unur

(e-mail address removed) (Kevin Joseph) wrote in
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 ?

For starters, you don't have

use strict;
use warnings;

which would have enabled you to detect an error below.
$p = Net::ping->new(icmp) ;

Notice something wrong here?

Please do not post code without 'strict' and 'warnings'.

I observed the same behavior testing on my home network. The issue
disappears the moment I reach outside my home network. Incidentally, the
Win32 command line ping also shows the same behavior. Thus, it appears as
though this is not a Perl issue.

Sinan.
 
K

Kevin Joseph

Hi Sinan,

Thanks for responding. Note that when I run the exact same code on
Linux, it works just fine. Dont know why it does not work in Win2k.

A little more research revealed that the sleep statement is causing a
problem. If I dont have a sleep statement, it works fine. In place of
a sleep statement if I have a "system(pause)" statement, I get the
same results. Pretty strange.

Kevin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top