in reply to Re: Re: Re: Net:Ping HELP!
in thread Net:Ping HELP!

I could swear on my life that i tried putting in "icmp" and it didn't make a difference, however I tried you snippet and it worked perfectly!!!! Thank you so much.


I have also come up with an alternative way of doing this without using Net::Ping, although I have heard that it is better to use Net::Ping for various reasons. for those who are interested, see my code below.


your code
#!/usr/bin/perl -w use strict; use Net::Ping; my $host = "127.0.0.1"; my $ping=Net::Ping->new("icmp"); if ($ping->ping($host,2)){ print "$host is alive"; }else{ print "$host unreachable" }

My alternative code (very sloppy but it did the trick)
#!/usr/bin/perl -w use strict; checkup(); sub checkup { my $host = "209.94.100.100"; my $packloss = `ping -c 1 -s 1 $host | grep loss | awk '{print \$7}'`; $packloss = substr($packloss,0,length($packloss) -1); if ($packloss ne "100%") { print "$host is up with $packloss packet loss\n"; }else { print "$host is down with $packloss packet loss\n"; }