| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
cwf8
10年前发布

C#获得机器的Mac地址

需要调用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);  }