simple/snmp/list-mac-port

58 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl -w
#
2005-11-17 15:57:43 +01:00
# $Header: /usr/local/src/master/simple/snmp/list-mac-port,v 1.3 2005-11-17 14:57:43 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];
2005-11-17 15:57:43 +01:00
# 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 matrix-0-1 SNMPv2-SMI::mib-2.17.4.3.1.2 |";
open (W, $cmnd)
or die "cannot invoke snmpwalk: $!";
while(<W>) {
2005-11-17 15:57:43 +01:00
chomp;
my ($p, $port) = split / = /;
2005-11-17 15:57:43 +01:00
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.
2005-11-17 15:57:43 +01:00
print "$switch\t$mac\t$port\n";
}
# $Log: list-mac-port,v $
2005-11-17 15:57:43 +01:00
# 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
2005-05-25 12:55:36 +02:00
# 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.
#