#!/usr/bin/perl -w # # # mac-bp-ifIndex.pl - a test script to gather the 1.3.6.1.2.1.17.4.3.1.2 OID # and the 1.3.6.1.2.1.17.1.4.1.2 OID information from switches # (via snmp polls) then merge the tuples to create a single # MAC -> ifIndex pairs list. # # # use strict; my $depot_dir="/nms/depot"; my $comm_string="xxx"; my $switch_list="/nms/switch_fetch/switch_list"; my $switch; my $mac; my $bp; my $bp2; my $ifIndex; my $snmpwalk; my (%mactobp, %bptoifIndex); open (SWITCH, "$switch_list") || die "Can't open $switch_list file"; open (LOG, ">$depot_dir/mac-bp-ifIndex.txt") || die "Can't open $depot_dir/mac-bp-ifIndex.txt file"; while () { chomp($switch="$_"); $snmpwalk="/usr/local/bin/snmpwalk -c $comm_string $switch "; open(MACtoBP, "$snmpwalk .1.3.6.1.2.1.17.4.3.1.2 |") || die "can't do .1.3.6.1.2.1.17.4.3.1.2: $!\n"; while () { /SNMPv2-SMI::mib-2.17.4.3.1.2.(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\d+)\s+\=\s+\w+:\s(\d+)$/gm; $mac=sprintf ("%lx:%lx:%lx:%lx:%lx:%lx",$1, $2, $3, $4, $5, $6); $bp=$7; %mactobp = ( $mac => "$bp" ); # } open(BPtoifIndex, "$snmpwalk .1.3.6.1.2.1.17.1.4.1.2 |") || die "can't do .1.3.6.1.2.1.17.1.4.1.2: $!\n"; while () { /SNMPv2-SMI::mib-2.17.1.4.1.2.(\d+)\s+\=\s+\w+:\s(\d+)$/gm; $bp2=sprintf ("%d",$1); $ifIndex=sprintf ("%d",$2); %bptoifIndex = ( $bp2 => "$ifIndex" ); # } for my $mac (keys %mactobp) { if (exists $bptoifIndex{$bp} ) { $mactobp{$mac} = $bptoifIndex{$ifIndex}; print "$mac -> $ifIndex\n"; } } } } } close MACtoBP; close BPtoifIndex; close LOG; close SWITCH;