line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cisco::SNMP::ARP; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################################################## |
4
|
|
|
|
|
|
|
# AUTHOR = Michael Vincent |
5
|
|
|
|
|
|
|
# www.VinsWorld.com |
6
|
|
|
|
|
|
|
################################################## |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
73547
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
656
|
use Net::SNMP qw(:asn1); |
|
1
|
|
|
|
|
81933
|
|
|
1
|
|
|
|
|
423
|
|
12
|
1
|
|
|
1
|
|
711
|
use Cisco::SNMP; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
574
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = $Cisco::SNMP::VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @ISA = qw(Cisco::SNMP); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
################################################## |
19
|
|
|
|
|
|
|
# Start Public Module |
20
|
|
|
|
|
|
|
################################################## |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _arpOID { |
23
|
0
|
|
|
0
|
|
0
|
return '.1.3.6.1.2.1.4.22.1' |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub arpOIDs { |
27
|
2
|
|
|
2
|
1
|
6
|
return qw(IfIndex PhysAddress NetAddress Type) |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub arp_clear { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my ($idx, $ip) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if (!defined $idx) { |
|
|
0
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "ifIndex required"; |
36
|
|
|
|
|
|
|
return undef |
37
|
0
|
|
|
|
|
|
} elsif ($idx !~ /^\d+$/) { |
38
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid ifIndex `$idx'"; |
39
|
|
|
|
|
|
|
return undef |
40
|
0
|
|
|
|
|
|
} |
41
|
0
|
0
|
|
|
|
|
if (!defined $ip) { |
|
|
0
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "IP address required"; |
43
|
|
|
|
|
|
|
return undef |
44
|
0
|
|
|
|
|
|
} elsif ($ip !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) { |
45
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Invalid IP Address `$ip'"; |
46
|
|
|
|
|
|
|
return undef |
47
|
0
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $s = $self->session; |
50
|
0
|
|
|
|
|
|
my $r = $s->set_request( |
51
|
|
|
|
|
|
|
_arpOID() . ".4.$idx.$ip", INTEGER, 2 |
52
|
|
|
|
|
|
|
); |
53
|
0
|
0
|
|
|
|
|
if (!defined $r) { |
54
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = $s->error; |
55
|
|
|
|
|
|
|
return undef |
56
|
0
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
|
return $r->{_arpOID() . ".4.$idx.$ip"} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub arp_info { |
61
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
62
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $session = $self->{_SESSION_}; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my %ret; |
67
|
0
|
|
|
|
|
|
my @ARPKEYS = arpOIDs(); |
68
|
0
|
|
|
|
|
|
for my $oid (0..$#ARPKEYS) { |
69
|
0
|
|
|
|
|
|
$ret{$ARPKEYS[$oid]} = Cisco::SNMP::_snmpwalk($session, _arpOID() . '.' . ($oid+1)); |
70
|
0
|
0
|
|
|
|
|
if (!defined $ret{$ARPKEYS[$oid]}) { |
71
|
0
|
|
|
|
|
|
$Cisco::SNMP::LASTERROR = "Cannot get ARP `$ARPKEYS[$oid]' info"; |
72
|
|
|
|
|
|
|
return undef |
73
|
0
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my %ArpType = ( |
77
|
|
|
|
|
|
|
1 => 'OTHER', |
78
|
|
|
|
|
|
|
2 => 'INVALID', |
79
|
|
|
|
|
|
|
3 => 'DYNAMIC', |
80
|
|
|
|
|
|
|
4 => 'STATIC' |
81
|
|
|
|
|
|
|
); |
82
|
0
|
|
|
|
|
|
my @ArpInfo; |
83
|
0
|
|
|
|
|
|
for my $arp (0..$#{$ret{$ARPKEYS[0]}}) { |
|
0
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my %ArpInfoHash; |
85
|
0
|
|
|
|
|
|
for (0..$#ARPKEYS) { |
86
|
0
|
0
|
|
|
|
|
if ($_ == 1) { |
|
|
0
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
$ArpInfoHash{$ARPKEYS[$_]} = ($ret{$ARPKEYS[$_]}->[$arp] =~ /^\0/) ? unpack('H12', $ret{$ARPKEYS[$_]}->[$arp]) : (($ret{$ARPKEYS[$_]}->[$arp] =~ /^0x/) ? substr($ret{$ARPKEYS[$_]}->[$arp],2) : $ret{$ARPKEYS[$_]}->[$arp]) |
|
|
0
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} elsif ($_ == 3) { |
89
|
0
|
0
|
|
|
|
|
$ArpInfoHash{$ARPKEYS[$_]} = exists($ArpType{$ret{$ARPKEYS[$_]}->[$arp]}) ? $ArpType{$ret{$ARPKEYS[$_]}->[$arp]} : $ret{$ARPKEYS[$_]}->[$arp] |
90
|
|
|
|
|
|
|
} else { |
91
|
0
|
|
|
|
|
|
$ArpInfoHash{$ARPKEYS[$_]} = $ret{$ARPKEYS[$_]}->[$arp] |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
0
|
|
|
|
|
|
push @ArpInfo, \%ArpInfoHash |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
|
return bless \@ArpInfo, $class |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
for (arpOIDs()) { |
100
|
|
|
|
|
|
|
Cisco::SNMP::_mk_accessors_array_1('arp', $_) |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
1
|
|
8
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
154
|
|
104
|
|
|
|
|
|
|
# get_ direct |
105
|
|
|
|
|
|
|
my @OIDS = arpOIDs(); |
106
|
|
|
|
|
|
|
for my $o (0..$#OIDS) { |
107
|
|
|
|
|
|
|
*{"get_arp" . $OIDS[$o]} = sub { |
108
|
0
|
|
|
0
|
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my ($val1, $val2) = @_; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if (!defined $val1) { $val1 = 1 } |
|
0
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if (!defined $val2) { $val2 = '1.1.1.1' } |
|
0
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my $s = $self->session; |
114
|
0
|
|
|
|
|
|
my $r = $s->get_request( |
115
|
|
|
|
|
|
|
varbindlist => [_arpOID() . '.' . ($o+1) . '.' . "$val1.$val2"] |
116
|
|
|
|
|
|
|
); |
117
|
0
|
|
|
|
|
|
return $r->{_arpOID() . '.' . ($o+1) . '.' . "$val1.$val2"} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
################################################## |
122
|
|
|
|
|
|
|
# End Public Module |
123
|
|
|
|
|
|
|
################################################## |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |