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
.
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
.
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
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.