C#获得机器的Mac地址

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

需要调用windows api,iphlpapi.dll中的方法:

[DllImport("iphlpapi.dll", ExactSpelling = true)]
public static extern int SendARP(int DestIP, int SrcIP, [Out] byte[] pMacAddr, ref int PhyAddrLen);
public string GetMacAddress(string hostName)
{
    System.Net.IPAddress[] adrr = Dns.GetHostEntry(hostName).AddressList;
    byte[] by = new byte[6];
    int len = by.Length;
    int r = SendARP((int)adrr[0].Address, 0, by, ref len);
    return BitConverter.ToString(by, 0, 6);
}