G
George Mpouras
# scan a network in 2 seconds using fork. Very simplistic but with
potential !
#!/usr/bin/perl
use strict;
use warnings;
use feature qw/say/;
use Net:
ing;
use Net::IP;
my $threads = 255;
my $duration = 2;
my @ip_team = ();
$|= 1;
my $ip = new Net::IP ('192.168.0.1 - 192.168.0.254') or die "Could not
initiate object because ". Net::IP::Error() ."\n";
while ($ip) {
push @ip_team, $ip++ ->ip();
if ( $threads == @ip_team ) { Scan(@ip_team); @ip_team = () }
}
Scan(@ip_team);
sub Scan
{
my @Pids;
foreach my $ip (@_)
{
my $pid = fork();
die "Could not fork because $!\n" unless defined $pid;
if (0 == $pid)
{
my $ping = Net:
ing->new('icmp');
say "host $ip is up" if $ping->ping($ip, $duration);
$ping->close();
exit
}
else
{
push @Pids, $pid
}
}
foreach my $pid (@Pids) { waitpid($pid, 0) }
}
potential !
#!/usr/bin/perl
use strict;
use warnings;
use feature qw/say/;
use Net:
use Net::IP;
my $threads = 255;
my $duration = 2;
my @ip_team = ();
$|= 1;
my $ip = new Net::IP ('192.168.0.1 - 192.168.0.254') or die "Could not
initiate object because ". Net::IP::Error() ."\n";
while ($ip) {
push @ip_team, $ip++ ->ip();
if ( $threads == @ip_team ) { Scan(@ip_team); @ip_team = () }
}
Scan(@ip_team);
sub Scan
{
my @Pids;
foreach my $ip (@_)
{
my $pid = fork();
die "Could not fork because $!\n" unless defined $pid;
if (0 == $pid)
{
my $ping = Net:
say "host $ip is up" if $ping->ping($ip, $duration);
$ping->close();
exit
}
else
{
push @Pids, $pid
}
}
foreach my $pid (@Pids) { waitpid($pid, 0) }
}