The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME Net::Ping::Network - A modul to ICMP-request nodes in a network (or list) very fast


Import Net-Ping-Network and use the original Interface. Simply give a network address and a mask to the constructor new().

    use Net::Ping::Network;
    my $net = Net::Ping::Network->new("", 29);

Optionally the timeout in seconds (3), the amount of retries (3), the number of threads utilized (10) and the size in byte (56) of icmp-load can be specified.

    my $net = Net::Ping::Network->new("", 29, $timeout, $retries, $threads, $size);

To ping the hosts in the network use the doping() methode of your Net::Ping::Network methode. When Net::Ping::Network is done, you can get the results as hashref using the methode results().

    my $results = $net->results();
    #Since Version 1.62 you can simply    
    my ($results,$process_time = $net->doping();

The hashkey of $results hash_ref is the ip, the value is 1 for reachable, 0 for unreachable. The hashkey of $process_time is the ip, the value is a value in microseconds needed to process the ping. (It is the roundtrip-time of the ping. If no response is received its a value near the given timeout.)

The hash is not sorted in anyway, to sort a hash is useless. If you need sorted results try this:

1. get the Keys from the returned hashref (ips).

    my @unsorted_keys = keys %$results;

2. using a sort over the packed data. This is much fast then sort by every field.

    my @keys = sort { # sort list of ips accending
     pack('C4' => $a =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/)
     cmp pack('C4' => $b =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/) } @unsorted_keys;

    foreach my $key ( @keys ) {
        print "$key" . " is ";
        if ( $$results{"$key"} ) {
          print  "alive.\n";
        } else {
          print "unreachable!\n";

A list of all hosts to ping, can be gathered from the methode listAllHost()

    my  @all = $net->listAllHost();
    my $list = $net->listAllHost();

In list context listAllHost returns an array containing all hosts to ping. In scalar context this methode returns a whitespace separeted string of all IPs.

If you need the number of Host for a given netmask use my $x = $net->calchosts(); or my $y = calchost(22);

calchosts() calculates the max. number of host in a network with the given mask. The broadcast address is not a possible host, the network base address ist not a possible host.


The existing ping moduls are slow and can only handle one ping at a time. Net::Ping::Networks (Net::Ping::Multi) can handle even large ip ranges and entire networks. Depending of your computing power and memory you can scan a class c network in less then 5 seconds.

On a normal desktop computer and without any further tuning, one should be able to manage 2500-3000 ips in less then 5 minutes.

Threads are utilised to boost performace. Threads feel a still a little bit beta today.



creates a new Net::Ping::Network instance. Needs a network base address and netmask or an array of ips to ping. If a network base address and a mask is supplied, Net::Ping::Networks will build a List of all host-ips in the net automaticaly.

$n = Net::Ping::Network->new("", 29, [$timeout, $retries, $threads, $size]);


depending on the context it returns a list containig all possible Hosts in the network or a space seperated string.


executes the configured ping utilising the given parameters. As lower the amount auf pings per threads is, as faster the methode will return.


Calculates the amount of possible hosts for a Netmask, value between 0 and 32 is expected. Network-Address and Broadcast is removed, but a /32 has 1 Address.


Returns a Hashref of the Results. Keys are IPs, the Values are returncodes (0 for bad or 1 for ok).


Returns a Hashref of the per Host Process Time (PIND ROUNDTRIPTIME). Keys are the Host-IPs.


Copyright 2007-2009, Bastian Angerstein. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as PERL itself.



Threads are cpu and memory intensive and feel still beta. Have an extra eye on memory leaks. Net::Ping::Networks is a quick and dirty but easy to read and understand implementation. Documentation is in the Code.

Also it "could" lead into trouble to use a multithreaded modul in a multithreaded environment.


Bastian Angerstein -


net::ping, net::ping::external