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

Hi monks, i was looking for a program that can make ping to a range of a ip like 10.0.0.1-10.0.0.10 but i could not find nothing, so i think perl can make this job i found info about NET::PING module but my problem was to get the last element from the ip's address, if somebody can give me a hand, Thanks

Replies are listed 'Best First'.
Re: Pinging an ip range
by rob_au (Abbot) on Jan 25, 2003 at 07:20 UTC
    You may want to have a look at the snippet of code which I posted in the thread Iterate network hosts - Using this code, you could ping a range of hosts specified by network and subnet mask with the following code:

    use Net::Netmask; use Net::Ping::External qw/ ping /; ping( 'host' => $_ ) for ips( '10.0.0.0/29' ); sub ips { my $net = Net::Netmask->new(@_); wantarray ? $net->enumerate : \@{$net->enumerate}; }

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000001000100110"))'

Re: Pinging an ip range
by tstock (Curate) on Jan 25, 2003 at 05:30 UTC
    nmap -sP 10.0.0.1-10

    tstock
      If you do decide to use nmap's output, check out its spiffy XML output:
      use XML::Simple qw(XMLin); use Data::Dumper; my($xml) = XMLin(scalar(`nmap -oX - -sP 10.0.0.0-50`)); print(Dumper(\$xml));
      Staunch
Re: Pinging an ip range
by fokat (Deacon) on Jan 26, 2003 at 03:14 UTC

    You can also do this...

    use NetAddr::IP; use Net::Ping::External qw/ping/; ping( 'host' => $_ ) for map { $_->addr } NetAddr::IP->new("10.0.0.0/24")->hostenum;

    ... which is a bit shorter.

    Best regards

    -lem, but some call me fokat