Whether you use Nmap::Parser
or Nmap::Scanner
, you have to run the same scan with Nmap, so there is no speed difference between the two.
Here's an example using Nmap::Scanner
which does approximately what you want, reporting the status of the hosts and attempting to OS fingerprint them if they are up, storing the results in a hash. You should be able to extend it as needed.
#!/usr/bin/perl
use strict;
use warnings;
use Nmap::Scanner;
my %network_status;
my $scanner = new Nmap::Scanner;
$scanner->register_scan_complete_event(\&scan_completed);
$scanner->guess_os();
$scanner->scan('-O 192.168.*.*');
foreach my $host ( keys %network_status ) {
print "$host => $network_status{$host}\n";
}
sub scan_completed {
my $self = shift;
my $host = shift;
my $hostname = $host->hostname();
my $addresses = join(',', map {$_->addr()} $host->addresses());
my $status = $host->status();
print "$hostname ($addresses) is $status ";
my $os_name = 'unknown OS';
if ( $status eq 'up' ) {
if ( $host->os() && $host->os()->osmatches() ) {
my ($os_type) = $host->os()->osmatches();
$os_name = $os_type->name();
}
print "($os_name)";
}
print "\n";
$network_status{$addresses} = $os_name;
}