Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
Perl-Sensitive Sunglasses
 
PerlMonks  

Net::Ping results question

by traveler (Parson)
on Aug 22, 2007 at 16:07 UTC ( #634407=perlquestion: print w/ replies, xml ) Need Help??
traveler has asked for the wisdom of the Perl Monks concerning the following question:

I am using Net::Ping to get a host's response time:
use strict; use warnings; use Net::Ping; my $ping = Net::Ping->new('icmp',2); $ping->hires; my ($ret1,$delay1,undef) = $ping->ping($local); print "($ret1,$delay1)\n";
$local is the IP of a host on the local network.

I get $ret always == 1 (so the ping was "successful"). $delay1 can be 0, 2.0, or some reasonable delay. The host is not "close" so a 0 second delay is unreasonable. A delay of 2.0 clearly means the host is not reachable. What is the difference between 0 and 2 given that $ret is always 1?

Comment on Net::Ping results question
Select or Download Code
Re: Net::Ping results question
by ikegami (Pope) on Aug 22, 2007 at 16:50 UTC

    The docs clearly say the timeout must be greater than zero. If it is zero, it happens to be treated as if it was missing. The default value when it's missing is 5 seconds. Try 0.001 instead of 0.

    Update: Nevermind. Misread the problem.

      My timeout is set to 2 in the code above bacause of that limit. (It is set in the constructor.)

        You said your problem is that you were getting the same result for 2 and 0. I explained that 0 really meant 5. The unmentioned conclusion is that if you were able to successfully ping a machine with a 2 second wait, then you'll also be successful if you wait for 5 seconds, so it's no surprise you get a "success" result with both values.

        Update: Nevermind. Misread the problem

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://634407]
Approved by andyford
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-04-20 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls