I'm trying to convert IP address to MAC address and then convert it to byte array. I'm stuck in the first part and not sure how to do this. I seen some search results talking about System.Net.NetworkInformation.NetworkInterface
but not sure how to use it.
This is my code which needs MAC byte array. How to do this?
[DllImport("iphlpapi.dll", ExactSpelling = true)]
public static extern int SendARP(int DestIP, int SrcIP, byte[] pMacAddr, ref uint PhyAddrLen);
private void Ping(IPAddress address)
{
byte[] macAddr = new byte[6];
uint macAddrLen = uint.Parse(macAddr.Length.ToString());
if (SendARP(int.Parse(address.ToString()), 0, macAddr, ref macAddrLen) == 0)
{
//SUCCESS!
}
}
Get about about what you try to do. It isakin to translate your phone number to the name of the street - there is NO correlation between them.
The MAC address is coded in the ethernet level driver while the IP address is an artificial construct higher up by the IP protocol. THey ahve ZERo relationship. Routers find the MAC addresses to send IP packets to via aprotocol (ARP - Address Resolution Protocol) and this can not cross network segments.