
mutew
By: a guest on
May 30th, 2009 | syntax:
Perl | size: 0.84 KB | hits: 61 | expires: Never
#!/usr/bin/perl
use strict;
use warnings;
## Scan a 24bit CIDR network for pingable hosts
use 5.10.0;
use Net::Ping;
my $ipRange = shift or die "Usage: pingrng <IP Address>\n";
my @ipSubset = split /\./, $ipRange;
#Verify IP Address range
for (@ipSubset) {
die "Invalid IP adress - $ipRange\n"
if not $_ || ($_ < 0 || $_ > 255);
}
my $kidpid;
for (1 .. 254) {
my $currIP = join ".", (@ipSubset[0,1,2], $_);
if ($kidpid) {
#Parent process
}
else {
#Child process
my $pingConn = Net::Ping->new(); #TCP
say "$currIP up" if $pingConn->ping($currIP);
$pingConn->close();
#Nothing else to do
}
}
say "Finished scanning $ipRange/24";