/[pxelator]/lib/PXElator/nmap.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/nmap.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 482 - (show annotations)
Sat Jan 23 18:31:14 2010 UTC (14 years, 2 months ago) by dpavlin
File size: 1232 byte(s)
use store::audit proxy all over the place

1 package nmap;
2
3 use warnings;
4 use strict;
5
6 use XML::Simple;
7 use Data::Dump qw/dump/;
8 use store;
9
10 use client;
11
12 sub scan {
13 my $what = shift;
14
15 my $path = $what;
16 $path =~ s{[^\w\d\.]+}{_}g;
17 $path = "/tmp/nmap.$path";
18
19 warn "# scan $what";
20
21 unlink $path if -f $path;
22
23 system("nmap -O -oX $path $what");
24
25 my $nmap = XMLin(
26 "$path",
27 KeyAttr => { address => 'addrtype' },
28 ForceArray => [ 'host', 'address', 'osmatch', 'port' ],
29 );
30
31 store::audit( $what, $nmap );
32
33 my $count = 0;
34
35 my $port_name = {
36 16992 => 'amt',
37 4445 => 'asterisk',
38 7777 => 'pxelator',
39 };
40
41 while ( my $host = shift @{ $nmap->{host} } ) {
42
43 warn '# host ',dump( $host );
44
45 my $ip = $host->{address}->{ipv4}->{addr} || die "ipv4";
46
47 if ( my $mac = $host->{address}->{mac}->{addr} ) {
48 print "$ip\t$mac\n";
49 client::save_ip_mac( $ip, $mac );
50 }
51
52 if ( my $os = $host->{os}->{osmatch}->[0]->{name} ) {
53 client::conf( $ip, 'os' => $os );
54 }
55
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;
58
59 $count++;
60 }
61
62 warn "# finish $count hosts";
63
64 return $count;
65 }
66
67 1;

  ViewVC Help
Powered by ViewVC 1.1.26