Re: [tkined] Getting MAC address off Cisco Switch

John Stumbles (J.D.Stumbles@reading.ac.uk)
Thu, 7 Oct 1999 16:46:02 +0100 (BST)

Jan,

I have also been using the dot1d tables, using snmpwalk (more or
less as from the scotty/examples directory) with a perl script to
manipulate it all into a table. (Code appended - excuse the bandwidth.) I
used perl because I am more familiar with that and was able to produce
working code quickly. The code uses hashes of arrays which I don't know
how to do at all in Tcl (not that I'm that good at it in Perl :-).

How are you getting the table you show below? Do you have
Scotty/Tcl code to do it? I would be interested to see how.

On Tue, 5 Oct 1999 Jan.Klingel@edag-us.com wrote:

> Hi there,
>
> the dot1dTpFdb table contains exactly the same information. The following
> example are the first five lines out of this table. Port 26 (this is the uplink
> port) learnt 3 MAC addresses, port 2 knows one and port 6 knows one. Now some
> ports are missing in this table and some MAC addresses are collected together on
> port 26.
>
> dot1dTpFdbAddress dot1dTpFdbPort dot1dTpFdbStatus
> 00:E0:2B:62:31:00 26 learned
> 08:00:20:71:4D:1D 26 learned
> 00:10:4B:0B:9E:DD 26 learned
> 08:00:69:0B:B0:28 2 learned
> 00:00:AA:55:90:D9 6 learned

regards,

--
John Stumbles                                      j.d.stumbles@reading.ac.uk
I.T. Services Centre,   University of Reading  http://www.rdg.ac.uk/~visstmbl 
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

# call this function with name or address of switch

sub get_device_MAC_table { my ($device)=@_; # walk dot1dTpFdbPort to get hash of port{dotted.number} # and walk dot1dTpFdbAddress to get hash of address{dotted.number} $input = "snmpwalk $device dot1dTpFdbPort"; open (IN, "$input|") || die "Could not open $input\n$!"; $port_recs=0; $ifIndex={}; while (<IN>) { # records are like # dot1dTpFdbPort.0.0.232.206.242.151 : 9 # extract data (dotted.number, ifIndex): next unless (($dotted_number, $ifIndex) = /dot1dTpFdbPort\.(\S+)\s+:\s+(\d+)/); $ifIndex{$dotted_number} = $ifIndex; $port_recs++; } close IN;

$input = "$SNMPWALK $device dot1dTpFdbAddress"; open (IN, "$input|") || die "Could not open $input\n$!"; $MAC_recs=0; $mac={}; while (<IN>) { # records are like # dot1dTpFdbAddress.0.0.232.206.242.151 : 00:00:E8:CE:F2:97 # extract data next unless (($dotted_number, $MAC) = /dot1dTpFdbAddress\.(\S+)\s+:\s+(\S+)/); $mac{$dotted_number} = $MAC; $MAC_recs++; } close IN;

# correlate the port{dotted.number} and mac{dotted.number} hashes # to produce hash tables of PORT{MAC} and MAC{PORT} foreach $key (keys %mac) { push @{ $PORT{$mac{$key}} } , $ifIndex{$key}; } foreach $key (keys %ifIndex) { push @{ $MAC{$ifIndex{$key}} } , $mac{$key}; } return (\%PORT, \%MAC); foreach $m (sort keys %PORT) { print "$m\t[", join ( "][", @{ $PORT{$m} } ) , "]\n"; } foreach $p (sort keys %MAC) { print "$p\t", join ( "\n\t", @{ $MAC{$p} } ) , "\n"; } } # end of sub get_device_MAC_table

--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.