my $host;
$=1;
for $host (@hosts){
$_=shift(@hosts);
# scan a class C
if(/^([^.]+).([^.]+).([^.]+)$/){
my $i;
print "Expanding class C $_n" if($DEBUG);
for($i=1;$i<255;$i++){
my $thost="$_.$i";
push @hosts,$thost;
}
}
else{
push @hosts,$_;
}
}
my @pids;
my $npids=0;
for $host (@hosts){
my $pid;
$pid=fork();
if($pid>0){
$npids++;
if($npids>=$MAX_PROCESSES){
for(1..($MAX_PROCESSES)){
$wait_ret=wait();
if($wait_ret>0){
$npids--;
}
}
}
next;
}elsif(undef $pid){
print "fork errorn" if ($DEBUG);
exit(0);
}else{
my($proto,$port,$sin,$ip);
print "Trying $hostn" if ($DEBUG);
$0="(checking $host)";
# kill thread on timeout
local $SIG{'ALRM'} = sub { exit(0); };