GreyOwl has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl5 -w use Net::Ping; my @pinglist = ( "svhappy" ,"w01b0rji" ,"w01b0rji.cube.fred.ch" ,"svmoloch.flur.fred.ch" ,"160.69.125.142" ); $p = Net::Ping->new(); foreach $h (@pinglist) { chomp (my $res = `ping $h`); if ($res) {print "$h \`ping\` OK :\t$res\n"} else {print "$h \`ping\` NOK\n"} if ($p->ping($h)) {print "$h \$p->ping OK\n"} else {print "$h \$p->ping NOK\n"} print "\n"; } $p->close();
...gives following results:
(svmoloch:szhxrv) $ ./test.pl
ping: unknown host svhappy
svhappy `ping` NOK
svhappy $p->ping NOK
ping: unknown host w01b0rji
w01b0rji `ping` NOK
w01b0rji $p->ping NOK
w01b0rji.cube.fred.ch `ping` OK : w01b0rji.cube.fred.ch is alive
w01b0rji.cube.fred.ch $p->ping NOK
svmoloch.flur.fred.ch `ping` OK : svmoloch.flur.fred.ch is alive
svmoloch.flur.fred.ch $p->ping NOK
160.69.125.142 `ping` OK : 160.69.125.142 is alive
160.69.125.142 $p->ping NOK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected results from ping
by xmath (Hermit) on Mar 04, 2003 at 14:51 UTC | |
by Rhose (Priest) on Mar 04, 2003 at 14:59 UTC | |
by Rhose (Priest) on Mar 04, 2003 at 15:15 UTC | |
by xmath (Hermit) on Mar 04, 2003 at 15:19 UTC |