#!/usr/bin/perl -w # # $Header: /usr/local/src/master/simple/snmp/list-mac-port,v 1.4 2005-11-17 16:07:41 hjp Exp $ # # list mac/port mapping of a switch # use strict; sub usage { print STDERR "Usage: $0 switch\n"; exit(1); } if (@ARGV != 1) {usage();} my $switch = $ARGV[0]; # UCD-snmp version: 4.2.3 #my $cmnd = "snmpwalk $switch public 17.4.3.1.2 |"; # NET-SNMP version: 5.0.9 my $cmnd = "snmpwalk -m ALL -v 1 -c public -O n $switch SNMPv2-SMI::mib-2.17.4.3.1.2 |"; open (W, $cmnd) or die "cannot invoke snmpwalk: $!"; while() { chomp; my ($p, $port) = split / = /; if ($port =~ /INTEGER: (\d+)/) { $port = $1; } my @p = split(/\./, $p); my $mac = join(":", map { sprintf("%02x", $_) } @p[-6 .. -1]); next if ($mac =~ /^00:e0:63:/); # Ignore internal MAC addresses # of Enterasys switches. print "$switch\t$mac\t$port\n"; } # $Log: list-mac-port,v $ # Revision 1.4 2005-11-17 16:07:41 hjp # Ups. hardcoding the switch isn't that great. # # Revision 1.3 2005/11/17 14:57:43 hjp # Adapted for NET-SNMP version: 5.0.9 # # Revision 1.2 2005/05/25 10:55:36 hjp # s/Id/Header/ to get full path. # # Revision 1.1 2003/12/03 13:51:47 hjp # Added list-mac-port. # bay-mac-port is obsolete, won't be installed any more. # # Revision 1.1 2001/04/11 14:31:29 hjp # mac-port: convert mac address to switch port using snmp. #