Nmap-Parser - Using callback functions to parse nmap scans with Nmap-Parser

Posted on Wed Jun 1 21:15:59 2005 by apersaud
Using callback functions to parse nmap scans with Nmap-Parser

This is probably the easiest way to write a script with using Nmap::Parser, if you don't need the general scan information. During the parsing process, the parser will obtain information of every host from the xml scan output. The callback function is called after completely parsing a single host. When the callback returns (or you finish doing what you need to do for that host), the parser will delete all information of the host it had sent to the callback. This callback function is called for every host that the parser encounters.

use Nmap::Parser; my $np = new Nmap::Parser; #NOTE: the callback function must be setup before parsing beings $np->register_host_callback( \&my_function_here ); #parsing will begin $np->parsefile('scanfile.xml'); sub my_function_here { #you will receive a Nmap::Parser::Host object for the current host #that has just been finished scanned (or parsing) my $host = shift; print 'Scanned IP: '.$host->addr()."\n"; # ... do more stuff with $host ... #when this function returns, the Nmap::Parser will delete the host #from memory }
Write a response