7 use Data::Dump qw/dump/;
16 $path =~ s{[^\w\d\.]+}{_}g;
17 $path = "/tmp/nmap.$path";
21 unlink $path if -f $path;
23 system("nmap -O -oX $path $what");
27 KeyAttr => { address => 'addrtype' },
28 ForceArray => [ 'host', 'address', 'osmatch', 'port' ],
31 CouchDB::audit( $what, $nmap );
41 while ( my $host = shift @{ $nmap->{host} } ) {
43 warn '# host ',dump( $host );
45 my $ip = $host->{address}->{ipv4}->{addr} || die "ipv4";
47 if ( my $mac = $host->{address}->{mac}->{addr} ) {
49 client::save_ip_mac( $ip, $mac );
52 if ( my $os = $host->{os}->{osmatch}->[0]->{name} ) {
53 client::conf( $ip, 'os' => $os );
56 my @ports = map { [ $_->{portid}, $_->{protocol}, $port_name->{$_->{portid}} || $_->{service}->{name} ] } @{ $host->{ports}->{port} };
57 client::conf( $ip, 'ports' => join("\n", map { join("\t", @$_) } @ports) ) if @ports;
62 warn "# finish $count hosts";