line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::IP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
13306
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
913
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
61876
|
|
|
1
|
|
|
|
|
321
|
|
12
|
1
|
|
|
1
|
|
512
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
880
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _ipOID { |
23
|
0
|
|
|
0
|
|
0
|
return '.1.3.6.1.2.1.4' |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub ipOIDs { |
27
|
3
|
|
|
3
|
1
|
15
|
return qw( |
28
|
|
|
|
|
|
|
Forwarding DefaultTTL InReceives InHdrErrors InAddrErrors |
29
|
|
|
|
|
|
|
ForwDatagrams InUnknownProtos InDiscards InDelivers OutRequests |
30
|
|
|
|
|
|
|
OutDiscards OutNoRoutes ReasmTimeout ReasmReqds ReasmOKs |
31
|
|
|
|
|
|
|
ReasmFails FragOKs FragFails FragCreates |
32
|
|
|
|
|
|
|
) |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub addrOIDs { |
36
|
2
|
|
|
2
|
1
|
6
|
return qw(Addr IfIndex NetMask BcastAddr ReasmMaxSize) |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub routeOIDs { |
40
|
2
|
|
|
2
|
1
|
5
|
return qw( |
41
|
|
|
|
|
|
|
Dest IfIndex Metric1 Metric2 Metric3 |
42
|
|
|
|
|
|
|
Metric4 NextHop Type Proto Age |
43
|
|
|
|
|
|
|
Mask Metric5 Info |
44
|
|
|
|
|
|
|
) |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ip_info { |
48
|
0
|
|
|
0
|
1
|
|
my ($self, $arg) = @_; |
49
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my %ret; |
54
|
0
|
|
|
|
|
|
my @IPKEYS = ipOIDs(); |
55
|
0
|
|
|
|
|
|
for my $oid (0..$#IPKEYS) { |
56
|
0
|
|
|
|
|
|
$ret{$IPKEYS[$oid]} = Cisco::SNMP::_snmpwalk($session, _ipOID() . '.' . ($oid+1)); |
57
|
0
|
0
|
|
|
|
|
if (!defined $ret{$IPKEYS[$oid]}) { |
58
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get IP `$IPKEYS[$oid]' info"; |
59
|
|
|
|
|
|
|
return undef |
60
|
0
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my %ForType = ( |
64
|
|
|
|
|
|
|
1 => 'forwarding', |
65
|
|
|
|
|
|
|
2 => 'not-forwarding' |
66
|
|
|
|
|
|
|
); |
67
|
0
|
|
|
|
|
|
my @IpInfo; |
68
|
0
|
|
|
|
|
|
for my $ip (0..$#{$ret{$IPKEYS[0]}}) { |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my %IpInfoHash; |
70
|
0
|
|
|
|
|
|
for (0..$#IPKEYS) { |
71
|
0
|
0
|
|
|
|
|
if ($_ == 0) { |
72
|
0
|
0
|
|
|
|
|
$IpInfoHash{$IPKEYS[$_]} = exists($ForType{$ret{$IPKEYS[$_]}->[$ip]}) ? $ForType{$ret{$IPKEYS[$_]}->[$ip]} : $ret{$IPKEYS[$_]}->[$ip] |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
|
$IpInfoHash{$IPKEYS[$_]} = $ret{$IPKEYS[$_]}->[$ip] |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
push @IpInfo, \%IpInfoHash |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
return bless \@IpInfo, $class |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
for (ipOIDs()) { |
83
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1('ip', $_) |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub ip_forwardingOn { |
87
|
0
|
|
|
0
|
1
|
|
return set_ipForwarding(shift, 1) |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub ip_forwardingOff { |
91
|
0
|
|
|
0
|
1
|
|
return set_ipForwarding(shift, 2) |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub addr_info { |
95
|
0
|
|
|
0
|
1
|
|
my ($self, $arg) = @_; |
96
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my %ret; |
101
|
0
|
|
|
|
|
|
my @ADDRKEYS = addrOIDs(); |
102
|
0
|
|
|
|
|
|
for my $oid (0..$#ADDRKEYS) { |
103
|
0
|
|
|
|
|
|
$ret{$ADDRKEYS[$oid]} = Cisco::SNMP::_snmpwalk($session, _ipOID() . '.20.1.' . ($oid+1)); |
104
|
0
|
0
|
|
|
|
|
if (!defined $ret{$ADDRKEYS[$oid]}) { |
105
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get address `$ADDRKEYS[$oid]' info"; |
106
|
|
|
|
|
|
|
return undef |
107
|
0
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my %AddrInfo; |
111
|
0
|
|
|
|
|
|
for my $ip (0..$#{$ret{$ADDRKEYS[0]}}) { |
|
0
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my %AddrInfoHash; |
113
|
0
|
|
|
|
|
|
for (0..$#ADDRKEYS) { |
114
|
0
|
|
|
|
|
|
$AddrInfoHash{$ADDRKEYS[$_]} = $ret{$ADDRKEYS[$_]}->[$ip] |
115
|
|
|
|
|
|
|
} |
116
|
0
|
|
|
|
|
|
push @{$AddrInfo{$ret{$ADDRKEYS[1]}->[$ip]}}, \%AddrInfoHash |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
0
|
|
|
|
|
|
return bless \%AddrInfo, $class |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
for (addrOIDs()) { |
122
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_hash_2('if', 'addr', $_) |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub route_info { |
126
|
0
|
|
|
0
|
1
|
|
my ($self, $arg) = @_; |
127
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my %ret; |
132
|
0
|
|
|
|
|
|
my @ROUTEKEYS = routeOIDs(); |
133
|
0
|
|
|
|
|
|
for my $oid (0..$#ROUTEKEYS) { |
134
|
0
|
|
|
|
|
|
$ret{$ROUTEKEYS[$oid]} = Cisco::SNMP::_snmpwalk($session, _ipOID() . '.21.1.' . ($oid+1)); |
135
|
0
|
0
|
|
|
|
|
if (!defined $ret{$ROUTEKEYS[$oid]}) { |
136
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get route `$ROUTEKEYS[$oid]' info"; |
137
|
|
|
|
|
|
|
return undef |
138
|
0
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my %RouteType = ( |
142
|
|
|
|
|
|
|
1 => 'other', |
143
|
|
|
|
|
|
|
2 => 'invalid', |
144
|
|
|
|
|
|
|
3 => 'direct', |
145
|
|
|
|
|
|
|
4 => 'indirect' |
146
|
|
|
|
|
|
|
); |
147
|
0
|
|
|
|
|
|
my %RouteProto = ( |
148
|
|
|
|
|
|
|
1 => 'other', |
149
|
|
|
|
|
|
|
2 => 'local', |
150
|
|
|
|
|
|
|
3 => 'netmgmt', |
151
|
|
|
|
|
|
|
4 => 'icmp', |
152
|
|
|
|
|
|
|
5 => 'egp', |
153
|
|
|
|
|
|
|
6 => 'ggp', |
154
|
|
|
|
|
|
|
7 => 'hello', |
155
|
|
|
|
|
|
|
8 => 'rip', |
156
|
|
|
|
|
|
|
9 => 'is-is', |
157
|
|
|
|
|
|
|
10 => 'es-is', |
158
|
|
|
|
|
|
|
11 => 'ciscoIgrp', |
159
|
|
|
|
|
|
|
12 => 'bbnSpfIgp', |
160
|
|
|
|
|
|
|
13 => 'ospf', |
161
|
|
|
|
|
|
|
14 => 'bgp' |
162
|
|
|
|
|
|
|
); |
163
|
0
|
|
|
|
|
|
my @RouteInfo; |
164
|
0
|
|
|
|
|
|
for my $ip (0..$#{$ret{$ROUTEKEYS[0]}}) { |
|
0
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
my %RouteInfoHash; |
166
|
0
|
|
|
|
|
|
for (0..$#ROUTEKEYS) { |
167
|
0
|
0
|
|
|
|
|
if ($_ == 8) { |
|
|
0
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
$RouteInfoHash{$ROUTEKEYS[$_]} = exists($RouteType{$ret{$ROUTEKEYS[$_]}->[$ip]}) ? $RouteType{$ret{$ROUTEKEYS[$_]}->[$ip]} : $ret{$ROUTEKEYS[$_]}->[$ip] |
169
|
|
|
|
|
|
|
} elsif ($_ == 9) { |
170
|
0
|
0
|
|
|
|
|
$RouteInfoHash{$ROUTEKEYS[$_]} = exists($RouteProto{$ret{$ROUTEKEYS[$_]}->[$ip]}) ? $RouteProto{$ret{$ROUTEKEYS[$_]}->[$ip]} : $ret{$ROUTEKEYS[$_]}->[$ip] |
171
|
|
|
|
|
|
|
} else { |
172
|
0
|
|
|
|
|
|
$RouteInfoHash{$ROUTEKEYS[$_]} = $ret{$ROUTEKEYS[$_]}->[$ip] |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
0
|
|
|
|
|
|
push @RouteInfo, \%RouteInfoHash |
176
|
|
|
|
|
|
|
} |
177
|
0
|
|
|
|
|
|
return bless \@RouteInfo, $class |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
for (routeOIDs()) { |
181
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1('route', $_) |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
561
|
|
185
|
|
|
|
|
|
|
# get_ direct |
186
|
|
|
|
|
|
|
my @OIDS = ipOIDs(); |
187
|
|
|
|
|
|
|
for my $o (0..$#OIDS) { |
188
|
|
|
|
|
|
|
*{"get_ip" . $OIDS[$o]} = sub { |
189
|
0
|
|
|
0
|
|
|
my $self = shift; |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
my $s = $self->session; |
192
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
193
|
|
|
|
|
|
|
varbindlist => [_ipOID() . '.' . ($o+1) . '.0'] |
194
|
|
|
|
|
|
|
); |
195
|
0
|
|
|
|
|
|
return $r->{_ipOID() . '.' . ($o+1) . '.0'} |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
@OIDS = addrOIDs(); |
200
|
|
|
|
|
|
|
for my $o (0..$#OIDS) { |
201
|
|
|
|
|
|
|
*{"get_addr" . $OIDS[$o]} = sub { |
202
|
0
|
|
|
0
|
|
|
my $self = shift; |
203
|
0
|
|
|
|
|
|
my ($val) = @_; |
204
|
|
|
|
|
|
|
|
205
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = '0.0.0.0' } |
|
0
|
|
|
|
|
|
|
206
|
0
|
|
|
|
|
|
my $s = $self->session; |
207
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
208
|
|
|
|
|
|
|
varbindlist => [_ipOID() . '.20.1.' . ($o+1) . '.' . $val] |
209
|
|
|
|
|
|
|
); |
210
|
0
|
|
|
|
|
|
return $r->{_ipOID() . '.20.1.' . ($o+1) . '.' . $val} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
@OIDS = routeOIDs(); |
215
|
|
|
|
|
|
|
for my $o (0..$#OIDS) { |
216
|
|
|
|
|
|
|
*{"get_route" . $OIDS[$o]} = sub { |
217
|
0
|
|
|
0
|
|
|
my $self = shift; |
218
|
0
|
|
|
|
|
|
my ($val) = @_; |
219
|
|
|
|
|
|
|
|
220
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = '0.0.0.0' } |
|
0
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
my $s = $self->session; |
222
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
223
|
|
|
|
|
|
|
varbindlist => [_ipOID() . '.21.1.' . ($o+1) . '.' . $val] |
224
|
|
|
|
|
|
|
); |
225
|
0
|
|
|
|
|
|
return $r->{_ipOID() . '.21.1.' . ($o+1) . '.' . $val} |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# set_ direct |
230
|
|
|
|
|
|
|
@OIDS = ipOIDs(); |
231
|
|
|
|
|
|
|
for my $o (0..1) { |
232
|
|
|
|
|
|
|
my $def = 1; |
233
|
|
|
|
|
|
|
if ($o == 1) { $def = 255 } |
234
|
|
|
|
|
|
|
*{"set_ip" . $OIDS[$o]} = sub { |
235
|
0
|
|
|
0
|
|
|
my $self = shift; |
236
|
0
|
|
|
|
|
|
my ($val) = @_; |
237
|
0
|
0
|
|
|
|
|
if (!defined $val) { $val = $def } |
|
0
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
my $s = $self->session; |
239
|
0
|
|
|
|
|
|
my $r = $s->set_request( |
240
|
|
|
|
|
|
|
_ipOID() . '.' . ($o+1) . '.0', INTEGER, $val |
241
|
|
|
|
|
|
|
); |
242
|
0
|
0
|
|
|
|
|
if (!defined $r) { |
243
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = $s->error; |
244
|
|
|
|
|
|
|
return |
245
|
0
|
|
|
|
|
|
} else { |
246
|
0
|
|
|
|
|
|
return $r->{_ipOID() . '.' . ($o+1) . '.0'} |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
################################################## |
252
|
|
|
|
|
|
|
# End Public Module |
253
|
|
|
|
|
|
|
################################################## |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
1; |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
__END__ |