| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package NetworkInfo::Discovery::NetBIOS; |
|
2
|
4
|
|
|
4
|
|
171853
|
use strict; |
|
|
4
|
|
|
|
|
12
|
|
|
|
4
|
|
|
|
|
185
|
|
|
3
|
4
|
|
|
4
|
|
27
|
use Carp; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
366
|
|
|
4
|
4
|
|
|
4
|
|
4427
|
use Net::NBName; |
|
|
4
|
|
|
|
|
73553
|
|
|
|
4
|
|
|
|
|
160
|
|
|
5
|
4
|
|
|
4
|
|
4341
|
use Net::Netmask; |
|
|
4
|
|
|
|
|
523449
|
|
|
|
4
|
|
|
|
|
535
|
|
|
6
|
4
|
|
|
4
|
|
13923
|
use NetworkInfo::Discovery::Detect; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
{ no strict; |
|
9
|
|
|
|
|
|
|
$VERSION = '0.05'; |
|
10
|
|
|
|
|
|
|
@ISA = qw(NetworkInfo::Discovery::Detect); |
|
11
|
|
|
|
|
|
|
} |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
NetworkInfo::Discovery::NetBIOS - NetworkInfo::Discovery extension to find NetBIOS services |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.05 |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use NetworkInfo::Discovery::NetBIOS; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $scanner = new NetworkInfo::Discovery::NetBIOS hosts => [ qw(192.168.0.0/24) ]; |
|
26
|
|
|
|
|
|
|
$scanner->do_it; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
for my $host ($scanner->get_interfaces) { |
|
29
|
|
|
|
|
|
|
printf "<%s> NetBios(node:%s zone:%s)\n", $host->{ip}, |
|
30
|
|
|
|
|
|
|
$host->{netbios}{node}, $host->{netbios}{zone}; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This module is an extension to C which can find |
|
37
|
|
|
|
|
|
|
hosts and services using the NetBIOS protocol. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 METHODS |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over 4 |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item new() |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Create and return a new object. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
B |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=over 4 |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=item * |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
C - expects a scalar or an arrayref of IP addresses in CIDR notation |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=back |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
B |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# with a scalar argument |
|
60
|
|
|
|
|
|
|
my $scanner = new NetworkInfo::Discovery::NetBIOS hosts => '192.168.0.0/24; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# with an arrayref |
|
63
|
|
|
|
|
|
|
my $scanner = new NetworkInfo::Discovery::NetBIOS hosts => [ qw(192.168.0.0/24) ]; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub new { |
|
68
|
|
|
|
|
|
|
my $class = shift; |
|
69
|
|
|
|
|
|
|
my $self = $class->SUPER::new(); |
|
70
|
|
|
|
|
|
|
my %args = @_; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$class = ref($class) || $class; |
|
73
|
|
|
|
|
|
|
bless $self, $class; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# add private fields |
|
76
|
|
|
|
|
|
|
$self->{_hosts_to_scan} = []; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# treat given arguments |
|
79
|
|
|
|
|
|
|
for my $attr (keys %args) { |
|
80
|
|
|
|
|
|
|
$self->$attr($args{$attr}) if $self->can($attr); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
return $self |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item do_it() |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Run the scan. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub do_it { |
|
93
|
|
|
|
|
|
|
my $self = shift; |
|
94
|
|
|
|
|
|
|
my @hosts = (); |
|
95
|
|
|
|
|
|
|
my $netbios = new Net::NBName; |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
for my $host (@{$self->{_hosts_to_scan}}) { |
|
98
|
|
|
|
|
|
|
for my $ip (Net::Netmask->new($host)->enumerate) { |
|
99
|
|
|
|
|
|
|
# trying to find status information on each IP address |
|
100
|
|
|
|
|
|
|
my %host = (); |
|
101
|
|
|
|
|
|
|
my $status = $netbios->node_status($ip); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
if($status) { |
|
104
|
|
|
|
|
|
|
$host{ip} = $ip; |
|
105
|
|
|
|
|
|
|
$host{mac} = $status->mac_address; |
|
106
|
|
|
|
|
|
|
$host{netbios} = {}; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
for my $rr ($status->names) { |
|
109
|
|
|
|
|
|
|
$host{netbios}{node} = $rr->name if $rr->suffix == 0x00 and $rr->G eq 'UNIQUE'; |
|
110
|
|
|
|
|
|
|
$host{netbios}{zone} = $rr->name if $rr->suffix == 0x00 and $rr->G eq 'GROUP'; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
push @hosts, { %host }; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# add found hosts |
|
119
|
|
|
|
|
|
|
$self->add_interface(@hosts); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# return list of found hosts |
|
122
|
|
|
|
|
|
|
return $self->get_interfaces |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item hosts() |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Add hosts or networks to the scan list. Expects addresses in CIDR notation. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
B |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$scanner->hosts('192.168.4.53'); # add one host |
|
132
|
|
|
|
|
|
|
$scanner->hosts('192.168.5.48/29'); # add a subnet |
|
133
|
|
|
|
|
|
|
$scanner->hosts(qw(192.168.6.0/30 10.0.0.3/28)); # add two subnets |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub hosts { |
|
138
|
|
|
|
|
|
|
my $self = shift; |
|
139
|
|
|
|
|
|
|
if(ref $_[0] eq 'ARRAY') { |
|
140
|
|
|
|
|
|
|
push @{$self->{_hosts_to_scan}}, @{$_[0]} |
|
141
|
|
|
|
|
|
|
} elsif(ref $_[0]) { |
|
142
|
|
|
|
|
|
|
croak "fatal: Don't know how to deal with a ", lc(ref($_[0])), "ref." |
|
143
|
|
|
|
|
|
|
} else { |
|
144
|
|
|
|
|
|
|
push @{$self->{_hosts_to_scan}}, @_ |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=over 4 |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item Don't know how to deal with a %sref. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
B<(F)> C was called with something it can't handle. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=back |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L, L |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AUTHOR |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Sébastien Aperghis-Tramoni, Esebastien@aperghis.netE |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 BUGS |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
171
|
|
|
|
|
|
|
C, or through the web interface at |
|
172
|
|
|
|
|
|
|
L. I will be notified, and then you'll automatically |
|
173
|
|
|
|
|
|
|
be notified of progress on your bug as I make changes. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Copyright 2004 Sébastien Aperghis-Tramoni, All Rights Reserved. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
180
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; # End of NetworkInfo::Discovery::NetBIOS |