How to convert IP address into MAC address byte array?
-
30-10-2019 - |
题
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!
}
}
没有正确的解决方案
不隶属于 StackOverflow