line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package NetworkInfo::Discovery::Detect; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
402
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
NetworkInfo::Discovery::Detect - Super Class for all detection modules |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
See NetworkInfo::Discovery::(Sniff|Traceroute|Scan) |
13
|
|
|
|
|
|
|
for examples. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
NetworkInfo::Discovery::Detect is set up to be the super class of all the detection modules. |
18
|
|
|
|
|
|
|
It sets up the methods for setting and getting the discovered information about interfaces, gateways, and subnets. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over 4 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item new |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
just set up lists for holding interfaces, subnets, and gateways |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
33
|
0
|
|
|
|
|
|
my %args = @_; |
34
|
0
|
|
|
|
|
|
my $err; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $self = {}; |
39
|
0
|
|
|
|
|
|
bless ($self, $class); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#set defaults |
42
|
0
|
|
|
|
|
|
$self->{'interfacelist'} = []; |
43
|
0
|
|
|
|
|
|
$self->{'gwlist'} = []; |
44
|
0
|
|
|
|
|
|
$self->{'subnetlist'} = []; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# for all args, see if we can autoload them |
47
|
0
|
|
|
|
|
|
foreach my $attr (keys %args) { |
48
|
0
|
0
|
|
|
|
|
if ($self->can($attr) ) { |
49
|
0
|
|
|
|
|
|
$self->$attr( $args{$attr} ); |
50
|
|
|
|
|
|
|
} else { |
51
|
0
|
|
|
|
|
|
print "error calling $class->$attr ( $args{$attr} ) : no method $attr \n"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=pod |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item do_it |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
this needs to be implemented in the subclass. |
63
|
|
|
|
|
|
|
it should do what ever it does to detect interfaces, gateways, or subnets adding them to our lists by using the add_* methods below. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
1
|
|
sub do_it { |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item get_interfaces |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item get_gateways |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item get_subnets |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
returns a list of hash references for interfaces, gateways, or subnets. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub get_interfaces { |
84
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return @{$self->{'interfacelist'}}; |
|
0
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
sub get_gateways { |
89
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return @{$self->{'gwlist'}}; |
|
0
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
sub get_subnets { |
94
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return @{$self->{'subnetlist'}}; |
|
0
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=pod |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item add_interface ($hashref) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item add_gateway ($hashref) |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item add_subnet ($hashref) |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
adds the hash ref to the list of interfaces, gateways, or subnets. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub add_interface { |
112
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
while (@_) { |
115
|
0
|
|
|
|
|
|
push (@{$self->{'interfacelist'}}, shift); |
|
0
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub add_gateway { |
120
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
while (@_) { |
123
|
0
|
|
|
|
|
|
push (@{$self->{'gwlist'}}, shift); |
|
0
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub add_subnet { |
128
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
while (@_) { |
131
|
0
|
|
|
|
|
|
push (@{$self->{'subnetlist'}}, shift); |
|
0
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Tom Scanlan |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 SEE ALSO |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 BUGS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Please send any bugs to Tom Scanlan |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
1; |