CPAN::Forum
Nmap-Parser - callback question
| Posted on Tue Mar 11 00:44:18 2008 by stinkingpig |
| callback question |
|
I'm trying to use callback and it doesn't seem to be working as documented. Here's the code, database work and logging removed for brevity. In my test scenario, I get an array of 9 addresses, and parsescan appears to be doing all 9, then calling nmap_read_results for each record after it gets the 9th scan. I expected it to call the subroutine after the 1st result, and again after the 2nd, and again after the 3rd... what's the story? thanks.
# If NMAP is around, let's go ahead and use it.
if ($nmap_present) {
# If we've got target nodes, we've got work to do.
if ($nmapcount) {
our $np = new Nmap::Parser;
$np->callback( \&nmap_read_results );
$np->parsescan($nmap, $nmap_options, @Address);
}
}
sub nmap_read_results() {
my $host = shift; #Nmap::Parser::Host object, just parsed
my $OS = "Unidentified";
my $newmac;
my $status = $host->status();
if ($status eq 'up') {
# Open the database
# Sometimes UNMANAGEDNODES doesn't have the MAC address, so let's save that now
$newmac = $host->mac_addr();
if ($newmac) {
# Sanitize the new MAC Address
$newmac =~ s/://;
$newmac =~ s/-//;
chomp($newmac);
# Update the MAC Address if it didn't exist before
# Get the MAC address manufacturer if available
my $vendor_id = $host->mac_vendor();
# Update the Manufacturer if it didn't exist before
}
# And now let's look at the OS Name
my $os = $host->os_sig();
$OS = $os->name;
$OS .= " \(" . $os->name_accuracy . "\)";
$goodcount++;
# Close the database
return 0;
} else {
# target was down
$badcount++;
return 1;
}
}
|
| Write a response |
(1)
]