How to get switch MAC address while implementing spanning tree protocol?
ARP packets are the way to go. Find the ip address of the switch you want, then send an ARP request to that ipaddress. You will receive a packet back mapping the ip address requested to the MAC address which owns that ip address.
The answer above is more of a how to translate an ip address to a MAC address, as that sounds like the gist of your question. STP generally is implemented using BPDU or bridge protocol data unit. If you haven't already you might want to check out:
http://computer.howstuffworks.com/lan-switch14.htm
http://en.wikipedia.org/wiki/Spanning_tree_protocol
http://en.wikipedia.org/wiki/Logical_Link_Control
BRIDGE ID: Each bridge is assigned an ID, called the bridge ID, that is defined as an 8-byte value split into two components. THe lowest six bytes are assigned the Ethernet MAC address of the bridge ports, and the highest two bytes are a configurable priority, call the bridge priority. -Understanding Linux network internals By Christian Benvenuti
See also
Troubleshooting campus networks By Priscilla Oppenheimer, Joseph Bardwell
You should first know that most Cisco switches will assign a unique bridge ID per VLAN based on a mac-address assigned to the switch. You can figure out what the bridge ID will be for a VLAN once you have determined what the assigned mac-address is. It is also good to remember that newer switches can use an extended system ID which is more than just the mac-address (as the other poster noted).
You can determine the base mac address and then calculate what the bridgeID will be for a particular VLAN based on the concept that the bridge ID for a particular VLAN will be the base Bridge ID + the vlan number. Example:
Base VLAN = 000.0001.0800
Bridge ID for VLAN 1 = 0000.0001.0801
Bridge ID for VLAN 300 = 0000.0001.092c
yes, it is in Hex format..
You could do this on a Cisco switch as follows:
1: show int | i line | address
This will give you your "base" mac address. You will notice all of the SVIs have the same mac address.
Vlan1 is up, line protocol is up
Hardware is EtherSVI, address is 000.0001.0800 (bia 000.0001.0800)
2: You could also just check spanning tree for the calculation directly:
Show span vlan 1 | b Bridge ID
Bridge ID Priority 8192
Address **000.0001.0801**
Hello Time 2 sec Max Age 20 sec Forward Delay 15 sec
Aging Time 300
The mac address under the Bridge ID is the one used for spanning tree calculation.