projects
/
pxelator
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6f3cbf4
)
nicer scan result path /tmp/nmap.what, store scan result in CouchDB
author
Dobrica Pavlinusic
<dpavlin@rot13.org>
Sat, 29 Aug 2009 12:55:34 +0000
(12:55 +0000)
committer
Dobrica Pavlinusic
<dpavlin@rot13.org>
Sat, 29 Aug 2009 12:55:34 +0000
(12:55 +0000)
lib/PXElator/nmap.pm
patch
|
blob
|
history
diff --git
a/lib/PXElator/nmap.pm
b/lib/PXElator/nmap.pm
index
7caac16
..
0ad47a3
100644
(file)
--- a/
lib/PXElator/nmap.pm
+++ b/
lib/PXElator/nmap.pm
@@
-5,6
+5,7
@@
use strict;
use XML::Simple;
use Data::Dump qw/dump/;
use XML::Simple;
use Data::Dump qw/dump/;
+use CouchDB;
use client;
use client;
@@
-13,35
+14,41
@@
sub scan {
my $path = $what;
$path =~ s{[^\w\d\.]+}{_}g;
my $path = $what;
$path =~ s{[^\w\d\.]+}{_}g;
+ $path = "/tmp/nmap.$path";
warn "# scan $what";
warn "# scan $what";
- system("nmap -O -oX /tmp/$path $what") == 0 || return;
+ unlink $path if -f $path;
+
+ system("nmap -O -oX $path $what");
my $nmap = XMLin(
my $nmap = XMLin(
- "
/tmp/
$path",
+ "$path",
KeyAttr => { address => 'addrtype' },
KeyAttr => { address => 'addrtype' },
- ForceArray => [ 'host', 'osmatch', 'port' ],
+ ForceArray => [ 'host', '
address', '
osmatch', 'port' ],
);
);
+ CouchDB::audit( $what, $nmap );
+
my $count = 0;
my $count = 0;
-
foreach my $host (
@{ $nmap->{host} } ) {
+
while ( my $host = shift
@{ $nmap->{host} } ) {
- warn dump( $host );
+ warn
'# host ',
dump( $host );
my $ip = $host->{address}->{ipv4}->{addr} || die "ipv4";
my $ip = $host->{address}->{ipv4}->{addr} || die "ipv4";
- my $mac = $host->{address}->{mac}->{addr} || die "mac";
- print "$ip\t$mac\n";
+ if ( my $mac = $host->{address}->{mac}->{addr} ) {
+ print "$ip\t$mac\n";
+ client::save_ip_mac( $ip, $mac );
+ }
- client::save_ip_mac( $ip, $mac );
if ( my $os = $host->{os}->{osmatch}->[0]->{name} ) {
client::conf( $ip, 'os' => $os );
}
if ( my $os = $host->{os}->{osmatch}->[0]->{name} ) {
client::conf( $ip, 'os' => $os );
}
- my @ports = map {
$_->{portid}
} @{ $host->{ports}->{port} };
- client::conf( $ip, 'ports' => join("\n", @ports) ) if @ports;
+ my @ports = map {
[ $_->{portid}, $_->{protocol}, $_->{service}->{name} ]
} @{ $host->{ports}->{port} };
+ client::conf( $ip, 'ports' => join("\n",
map { join("\t", @$_) }
@ports) ) if @ports;
$count++;
}
$count++;
}