use strict;
use warnings;
use IO::Socket;
use Net::Ping;

my @networks = ();
my %opt = ();
my $network = '';
my $pinghost = '';
my $ret = 0;
my $count = 0;

$| = 1;

# Parameter bearbeiten
for ($count = 0; $count <= $#ARGV; $count++) 
  {  push @networks, $ARGV[$count]; }

foreach $network (@networks) 
  {
  print "Scanning Network $network.0 \n";
  for $count (1 .. 254) 
    {
    $pinghost = $network . "." . $count;
    $ret = pinger($pinghost);
    print "  $pinghost"; 
    print " not" unless ($ret == 1);
    print " reachable\n";
    }
  }
exit;

sub pinger # (Host)
  {
  # Parameter: Host
  my $host = shift;         # zu pingender Host
  my $retval = 0;           # Ergebnis: 0 nicht erreicht, 1 erreicht, 2 Fehler
  # Neues Net-Ping Objekt
  my $p = Net::Ping->new('icmp');
  unless (defined $p) { die "*** can't create Net::Ping object $!";}

  # Exceptions auffangen
  eval
    {
    $retval = 1 if ($p->ping($host));
    if ($@)
      {
      print "*** Ping failed\n*** $@\n";
      $retval = 2;
      }
    $p->close;
    undef ($p);
    sleep(1);       # avoid network flooding
    return $retval;
    }
  }
