1

I want to get the MAC Address of another device using it's IP address,connected to the same network. I have the IP Address of the device.

I want a logic other than using iphlpapi.dll or by running command prompt in C# using arp -a ipaddress.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
user1879309
  • 39
  • 1
  • 4
  • 2
    What if `arp` is the only solution? – Patrick Hofman Dec 12 '14 at 08:44
  • 2
    Possible duplicate of http://stackoverflow.com/questions/3254126/how-to-get-mac-address-of-external-ip-in-c-sharp. – Patrick Hofman Dec 12 '14 at 08:45
  • But that's exactly what ARP is for - and it's not something you're supposed to care about. This is all the way down at the link layer, and you can have networks with no MACs - and of course, even if they do, it's only really going to work on LAN, link layer data usually doesn't cross network boundaries. Your application shouldn't really go deeper than IP. Why are you doing this? – Luaan Dec 12 '14 at 08:51

2 Answers2

1

You Must use the Address Resolution Protocol (ARP) in some form since it is designed to be the way to get the physical address of a device from its ip, but you've already ruled out using it from the command line. You might be able to get the results of a previous arp from the system routing tables.

Alternatively you use a pcap wrapper and send your own arp request to the device, this will then respond with it's MAC Address

James
  • 9,774
  • 5
  • 34
  • 58
1

To get MAC Address from another computer from same network your need to send ARP Request packet with specific IP Address, for example: You want to know MAC Address from IP (192.168.1.20) so your need to create raw packet like this:

Ethernet: Destination: FF:FF:FF:FF:FF:FF (broadcast address) Source: Your current MAC Address EthType: 0x0806 (ARP Type)

ARP (Ethernet Payload) Hardware Type: 1 (Ethernet) Protocol Type: 0x0800 (IP) Hardware Size: 6 Protocol Size: 4 Opcode: 1 (ARP Request) Sender MAC Address: Your current MAC Address (Same as at Ethernet part) Sender Protocol Address: Your current IP Address Target MAC Address: 00:00:00:00:00:00 (because you don't know target MAC Address yet) Target Protocol Address: 192.168.1.20 (The IP that you want to know about the Mac address)

If the target recieve this packet, target will reply with ARP Reply packet with the MAC Address included.