Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Net::Ping 2.63 Failing

by g_speran (Scribe)
on Jan 17, 2018 at 02:13 UTC ( [id://1207383]=perlquestion: print w/replies, xml ) Need Help??

g_speran has asked for the wisdom of the Perl Monks concerning the following question:

C:\temp>perl -MNet::Ping -e "print $Net::Ping::VERSION"; 2.63 Fails with getaddrinfo(192.168.10.991,,AF_INET) failed - nodename nor servname pr +ovided, or not known at C:\temp\ip.pl line 5. However, If I replace Ping.pm with version C:\temp>perl -MNet::Ping -e "print $Net::Ping::VERSION"; 2.43 It Is successful. C:\temp>ip.pl Result: Ping: 192.168.10.991 => #### UNPINGABLE #### Should this be raised as a bug? #!/usr/bin/perl use Net::Ping; $IP="192.168.10.991"; $p = Net::Ping->new("icmp"); if ($p->ping($IP)) { $RESULT="Ping: $IP => alive"; } else{ $RESULT= "Ping: $IP => #### UNPINGABLE ####"; } $p->close(); print "Result: $RESULT\n";

Replies are listed 'Best First'.
Re: Net::Ping 2.63 Failing
by huck (Prior) on Jan 17, 2018 at 03:12 UTC

    Could it be that 192.168.10.991 is not a valid TCPIP4 address

      works in one version, just not in the other. Also fails on an ip address of 10.240.220.331 in version 2.63 but works in version 2.43 for the same IP address. Should it be trying to actually validate an IP address or just ping it?
        Should it be trying to actually validate an IP address or just ping it?

        By my reading of the Net::Ping::ping() documentation, it should just ping it.

        That documentation says, in part:

        <quote>
        If the hostname cannot be found or there is a problem with the IP number, the success flag returned will be undef. Otherwise, the success flag will be 1 if the host is reachable and 0 if it is not. For most practical purposes, undef and 0 and can be treated as the same case.
        </quote>

        So, if the ping() function is dying, then it's not behaving as advertised - which makes it a bug.

        Cheers,
        Rob

        Please explain how can you ping an invalid address? What would you fill into the 32bits of the "Destination IP address"? How do you change the ascii 991 or 331 into a 8bit binary number?

Re: Net::Ping 2.63 Failing
by thanos1983 (Parson) on Jan 17, 2018 at 13:10 UTC

    Hello g_speran,

    You can simply follow the example of the perldoc Net::Ping with valid IP address.

    You do not need to use icmp unless you are root (unnecessary) you can use tcp and also you do not need if(){}else{} follow the example documented.

    Sample of code:

    Update: In case you want to know with precision on the ping time you can use this approach (similar to documentation):

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-24 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found