line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nmap::Scanner::Backend::Results; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 DESCRIPTION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
This class holds the results from a |
8
|
|
|
|
|
|
|
scan. Results include a host |
9
|
|
|
|
|
|
|
list (Nmap::Scanner::HostList) instance |
10
|
|
|
|
|
|
|
and an instance of Nmap::Scanner::NmapRun, |
11
|
|
|
|
|
|
|
which contains information about the |
12
|
|
|
|
|
|
|
scan. There are several methods in this |
13
|
|
|
|
|
|
|
class used by the scanner to populate the |
14
|
|
|
|
|
|
|
result set; the only three that will be of |
15
|
|
|
|
|
|
|
interest to most programmers are: |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 get_host_list() |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Returns an instance of |
20
|
|
|
|
|
|
|
Nmap::Scanner::HostList that can |
21
|
|
|
|
|
|
|
be iterated through to get the host |
22
|
|
|
|
|
|
|
objects found by the search. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Example (Assumes scanner |
25
|
|
|
|
|
|
|
instance is named $scanner): |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $results = $scanner->scan(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $host_list = $results->get_host_list(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
while (my $host = $host_list->get_next()) { |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
print "Found host named: " . $host->hostname() . "\n"; |
34
|
|
|
|
|
|
|
.. etc .. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 as_xml() |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Returns the results as a well-formed |
41
|
|
|
|
|
|
|
XML document. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Example (Assumes scanner instance |
44
|
|
|
|
|
|
|
is named $scanner): |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $results = $scanner->scan(); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
print $results->as_xml(); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 nmap_run() |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Returns the Nmap::Scanner::NmapRun |
53
|
|
|
|
|
|
|
instance with information about the |
54
|
|
|
|
|
|
|
scan itself. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
See the examples/ directory in the |
57
|
|
|
|
|
|
|
distribution for more examples. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
3
|
|
1079
|
use Nmap::Scanner::Host; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
use Nmap::Scanner::HostList; |
63
|
|
|
|
|
|
|
use Nmap::Scanner::Port; |
64
|
|
|
|
|
|
|
use Nmap::Scanner::NmapRun; |
65
|
|
|
|
|
|
|
use File::Spec; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
use strict; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { |
70
|
|
|
|
|
|
|
my $class = shift; |
71
|
|
|
|
|
|
|
my $you = {}; |
72
|
|
|
|
|
|
|
return bless $you, $class; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub debug { |
76
|
|
|
|
|
|
|
$_[0]->{'DEBUG'} = $_[1]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub nmap_run { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
@_ ? $self->{NMAP_RUN} = shift |
82
|
|
|
|
|
|
|
: return $self->{NMAP_RUN}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub add_host { |
86
|
|
|
|
|
|
|
$_[0]->{ALLHOSTS}->{($_[1]->addresses())[0]} = $_[1]; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub get_host { |
90
|
|
|
|
|
|
|
return $_[0]->{ALLHOSTS}->{$_[1]}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub get_all_hosts { |
94
|
|
|
|
|
|
|
return $_[0]->{ALLHOSTS}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub get_host_list { |
98
|
|
|
|
|
|
|
return new Nmap::Scanner::HostList($_[0]->{ALLHOSTS}); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub as_xml { |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
my $tmp = $self->get_host_list()->as_xml(); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $xml = "\n"; |
108
|
|
|
|
|
|
|
$xml .= $self->nmap_run()->as_xml($tmp); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
return $xml; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1; |