I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2008-03-10 22:44:18-07 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; } }
Direct Responses: Write a response