I am using perl to ping a list of nodes - with script below :
$p = Net::Ping->new("icmp");
if ($p->ping($host,1)){
print "$host is alive.\n";
}
else {
print "$host is unreacheable.\n";
}
$p->close();
This works fine however I want the script to tell me the reason why ping fails for the hosts that are not pingable.
Is there any way to print reason why $host is unreacheable using Net::Ping ?
If not is there a better way to ping list of hosts using Perl ?
I have tried same script using system ping for list of hosts I want to ping - for some of the hosts I am getting unknown hosts for others I am getting Host unreacheable. Do I need to do something like nslookup to check if host is in dns on the failed nodes - I was hoping I could do all with ping.
There are two thing you can test when ping some
If DNS does not resolve: ping vvv.google.no gives ping: unknown host vvv.google.no
If DNS is ok and it does not reply you get 4 packets transmitted, 0 received, 100% packet loss, time 3024ms
What I am looking to find out is if it is possible to check if result of ping failure using Net::Ping without parsing ping output. I want to know if host was unknown or if host was unreachable.