How to Get MAC Address of Directly Connected Network Neighbor – Ethernet Guide

ethernetmac address

I have a PC (in the successive diagrams pc1) equipped with a network interface that can be directly connected to another PC or to a managed switch.

I want to be able to get the MAC address of the closest device in the network.

Just to be more precise:

Situation #1

+-----+       +----------------+       +---------------+
| pc1 |-------| managed switch |-------| other devices |
+-----+       +----------------+       +---------------+

In this case, I want to get the MAC address of the managed switch.

Situation #2

+-----+       +-----+
| pc1 |-------| pc2 |
+-----+       +-----+

In this case, I want to get the mac address of pc2.

What can I use to retrieve the MAC address of the first network device?

Update

As far as I know, I cannot use ARP, because in PC1's ARP table, I'll see all the MAC addresses related to the IP addresses on the ethernet segment, but I have no way in general to know the IP address of the device at the other end of the cable (this is painful in the case of the switch). This is why I am looking for something like ping at the data link layer with a TTL of 1.

Best Answer

802.3 has no concept of "link partner identity". As such, you cannot reliably determine the MAC of any directly connecting device. However, there are higher level application protocols (CDP, LLDP, etc.) that attempt to address this.