script/cisco-arp.pl untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 71 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use warnings;
5 use Getopt::Long qw(:config no_ignore_case); #bundling
6 use Pod::Usage;
7  
8 use Cisco::SNMP::ARP;
9  
10 my %opt;
11 my ($opt_help, $opt_man);
12  
13 GetOptions(
14 'community=s' => \$opt{community},
15 'Clear=s' => \$opt{clear},
16 'help!' => \$opt_help,
17 'man!' => \$opt_man
18 ) or pod2usage(-verbose => 0);
19  
20 pod2usage(-verbose => 1) if defined $opt_help;
21 pod2usage(-verbose => 2) if defined $opt_man;
22  
23 # Make sure at least one arg was provided
24 if (!@ARGV) {
25 pod2usage(-verbose => 0, -message => "$0: host required\n")
26 }
27  
28 $opt{community} = $opt{community} || 'private';
29  
30 for (@ARGV) {
31 print "\n-- $_ --\n";
32  
33 my $cm;
34 if (!defined($cm = Cisco::SNMP::ARP->new(
35 hostname => $_,
36 community => $opt{community}
37 ))) {
38 printf "Error: %s\n", Cisco::SNMP::ARP->error;
39 next
40 }
41  
42 if (defined $opt{clear}) {
43 my ($idx, $ip) = split /,/, $opt{clear};
44 if (defined($cm->arp_clear($idx,$ip))) {
45 print "Cleared $ip ARP from interface index $idx\n"
46 } else {
47 printf "Error: %s\n", Cisco::SNMP::ARP->error
48 }
49 } else {
50 if (defined(my $arp = $cm->arp_info())) {
51 print "If Index | MAC Address | Net Address | Type\n";
52 print "---------|--------------|-----------------|-----\n";
53 for (0..$#{$arp}) {
54 printf "%8s | %-12s | %-15s | %s\n",
55 $arp->arpIfIndex($_),
56 $arp->arpPhysAddress($_),
57 $arp->arpNetAddress($_),
58 $arp->arpType($_)
59 }
60 print "\n"
61 } else {
62 printf "Error: %s\n", Cisco::SNMP::ARP->error
63 }
64 }
65  
66 $cm->close()
67 }
68  
69 __END__