Please reference the following code snippet:
if ($curoctet == $ipcount) { #we've reached the first one
@count = split ',', $scantargs;
@targs = reverse(@count);
foreach (@targs) {
$targ = $_;
#next if ($targ eq "");
$scancmd = qq!nmap -sS -P0 -p 1-65535 -T 5 -O -oN ./$targ.txt
$targ!;
#$foo = scanning();
$hostcheck = hostup();
if ($hostcheck == 1) {
$thread = threads->new(\&scanning); # Spawn the thread
$thread->detach;
} else {
print "$targ is down\n";
next;
}
}
($sc = $curip) =~ s/(.*\.)(.*$)/$2/; #set new start count variable
print "Encountered maxscans, need to wait till the PID's
complete\n";
$ipcount += $maxscans; #add another maxscans to the ips
$scantargs = "";
`sleep 2`;
}
sub hostup {
$isup = "";
$timeout = 1;
$p =
Net::Ping->new();
if ($p->ping($targ,
$timeout)) {
$isup = 1;
} else {
$isup = 0;
}
return $isup;
}
sub scanning {
print
"$scancmd\n";
}
When I run this I get the desired results, however, I have 3
questions:
1. How do I create a parent thread and join child threads to that
parent in order to control them?
2. How do I check the status of a thread to make sure it has
finished?
3. Why am I getting the following errors?
Attempt to free non-existent shared string 'detach' during global
destruction.
Attempt to free non-existent shared string 'new' during global
destruction.
Scalars leaked: -2
Unbalanced string table refcount: (1) for "new" during global
destruction.
Unbalanced string table refcount: (1) for "detach" during
global destruction.
Scalars leaked: 2
Am I exiting the script without properly closing the thread? And if so,
how do I close it?
-Wes
- [Perl-unix-users] Perl Installation wjnorth
- [Perl-unix-users] Perl Installation Bhanu Prasad