aixmike has asked for the wisdom of the Perl Monks concerning the following question:

I am using perl -v 5.8.8. I am trying to create a Linux utility to ping the ipaddresses in a simple text file, and display the ip addresses of those hosts that are 'alive'. I would like to send only 1 packet to help speed up the process. My problem is that at this point I cannot even get the example to at http://www.perlmonks.com/index.pl?node=net%3A%3Aping to work. I hope someone can give me some insight on how this code should work.
use Net::Ping; $p = Net::Ping->new(); print "$host is alive.\n" if $p->ping($host); $p->close(); $p = Net::Ping->new("icmp"); foreach $host (@host_array)

Replies are listed 'Best First'.
Re: net:ping problem
by zentara (Cardinal) on Aug 16, 2007 at 19:06 UTC
    You might be running into the problem that icmp pings must be run as root. Try 'tcp' instead of 'icmp'. Also, don't you need a port to ping?
    #!/usr/bin/perl use strict; use warnings; use Net::Ping; #tcp dosn't require root privileges my $p = Net::Ping->new('tcp'); $p->tcp_service_check(1); my $host = "192.168.0.1"; my $port = 80; $p->{'port_num'} = $port; print "The service on $host port $port is ", ($p->ping($host) ? "up" : "down"), ".\n";

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: net:ping problem
by fmerges (Chaplain) on Aug 16, 2007 at 20:26 UTC

    Hi,

    At the same time, keep in mind that also firewalls can block the incoming ICMP requests...

    Regards,

    fmerges at irc.freenode.net
Re: net:ping problem
by webfiend (Vicar) on Aug 16, 2007 at 19:05 UTC

    The local copy of the Net::Ping pod is outdated. Look for fresher documentation (and better examples) on CPAN, by searching for Net::Ping.

    Update: My original post was barely even in English, so I tried to make it more clear.