Search for MacAddress with an IP address regardless of platform

I need to find the MAC address of the device from which my device receives TCP requests, I get the IP address of the device using the tcp endpoint, but I need to find out the mac address of the device. My application will work on both windows and linux, so please suggest me a cross-platform method for finding mac address .. Any boost libraries will help me do the same ??

+5
source share
3 answers

Firstly, you cannot find the MAC address for any network interface that is not on the same local network. This information is not transmitted outside the router.

Unix arp, Unix, Windows, IP- MAC- , . .

arp -a

Windows - :

Interface: 9.175.198.236 --- 0x2
  Internet Address      Physical Address      Type
  9.175.198.129         00-1b-53-46-fa-7f     dynamic

Unix- :

foo.bar.com (10.27.68.72) at 00:50:56:AE:00:0B [ether] on eth0
baz.bar.com (10.27.68.77) at 00:50:56:AE:00:10 [ether] on eth0
? (10.27.68.1) at 00:50:5A:1B:44:01 [ether] on eth0

.

+5

, TCP MAC-.

, , :

  • arp , arp, MAC IP-. , , .

  • , , TCP. TCP. MAC- IP-.

+1

The arp source code is available in the link below, take the part of the code that interests you! This is c code, so it should work fine.

http://www.opensource.apple.com/source/network_cmds/network_cmds-328/arp.tproj/arp.c

+1
source

All Articles