我正在尝试将 IP 地址转换为 MAC 地址,然后将其转换为字节数组。我被困在第一部分,不知道该怎么做。我看到一些搜索结果在谈论System.Net.NetworkInformation.NetworkInterface
但不知道如何使用它。
这是我需要 MAC 字节数组的代码。这个怎么做?
[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!
}
}