Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Net::Ping results question

by traveler (Parson)
on Aug 22, 2007 at 16:07 UTC ( [id://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?

Replies are listed 'Best First'.
Re: Net::Ping results question
by ikegami (Patriarch) 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found