in reply to Net::Ping 2.63 Failing

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:

#!/usr/bin/perl use strict; use warnings; use Net::Ping; my @host_array = ("127.0.0.1", "10.0.0.10"); my $p = Net::Ping->new("tcp"); # $p->bind($my_addr); # Specify source interface of pings foreach my $host (@host_array) { print "$host is "; print "NOT " unless $p->ping($host, 2); print "reachable.\n"; sleep(1); } $p->close(); __END__ $ perl test.pl 127.0.0.1 is reachable. 10.0.0.10 is NOT reachable.

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

#!/usr/bin/perl use strict; use warnings; use Net::Ping; my @host_array = ('localhost', '10.0.0.10'); # High precision syntax (requires Time::HiRes) my $p = Net::Ping->new(); $p->hires(); foreach my $host (@host_array) { my ($ret, $duration, $ip) = $p->ping($host, 2); if ($ret) { printf("$host [ip: $ip] is alive (packet return time: %.2f ms)\n", 1000 * $duration); } else { printf("$host [ip: $ip] is not alive (packet return time: %.2f ms) +\n", 1000 * $duration); } sleep(1); } $p->close(); __END__ $ perl test.pl localhost [ip: 127.0.0.1] is alive (packet return time: 0.11 ms) 10.0.0.10 [ip: 10.0.0.10] is not alive (packet return time: 2002.36 ms +)

Hope this helps, BR.

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