如何从Windows-mobile获取MAC地址?

时间:2011-07-17 07:16:01

标签: c# windows-mobile

如何使用C#代码从Windows-mobile获取MAC地址?

提前谢谢

2 个答案:

答案 0 :(得分:4)

请通过以下粘贴链接,希望这可以帮助您找到设备的mac地址

MAC address in Compact Framework

How to Get MAC address programatically in c# for a windows mobile 6.0 device

答案 1 :(得分:3)

      [DllImport("iphlpapi.dll", SetLastError = true)]
  public static extern int GetAdaptersInfo(byte[] info, ref uint size);

  /// <summary>
  /// Gets the Mac Address
  /// </summary>
  /// <returns>the mac address or ""</returns>
  public static unsafe string GetMacAddress()
  {
     uint num = 0u;
     GetAdaptersInfo(null, ref num);
     byte[] array = new byte[(int)((UIntPtr)num)];
     int adaptersInfo = GetAdaptersInfo(array, ref num);
     if (adaptersInfo == 0)
     {
        string macAddress = "";
        int macLength = BitConverter.ToInt32(array, 400);
        macAddress = BitConverter.ToString(array, 404, macLength);
        macAddress = macAddress.Replace("-", ":");

        return macAddress;
     }
     else
        return "";
  }