How to get an answer from "ping -c 1 example.com"?
In BASH can I ping the server as such
for i in $MY_SERVER_LIST; do if ping -c 1 $i > /dev/null 2>&1; then # $i is alive fi done and I would like to do the same in Perl, but how to get an answer from
my $response = `ping -c 1 google.com > /dev/null 2>&1` Question
How can I do the same in Perl, but without using any packages like Net::Ping ?
I would use Net :: Ping!
use Net::Ping; $p = Net::Ping->new(); print "$host is alive.\n" if $p->ping($host); $p->close(); $p = Net::Ping->new("icmp"); $p->bind($my_addr); # Specify source interface of pings foreach $host (@host_array) { print "$host is "; print "NOT " unless $p->ping($host, 2); print "reachable.\n"; sleep(1); } $p->close();