首页 新闻 会员 周边 捐助

winform 怎么判断32位64位系统读取mac

0
悬赏园豆:20 [待解决问题]

 string mac = "";
            //获取网卡硬件地址
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc2 = mc.GetInstances();
            foreach (ManagementObject mo in moc2)
            {
                if ((bool)mo["IPEnabled"] == true)
                    mac = mo["MacAddress"].ToString();
                mo.Dispose();
            }
            return mac;

这个64位下获取不到mac

风尘々紫驿的主页 风尘々紫驿 | 初学一级 | 园豆:180
提问于:2011-03-24 09:08
< >
分享
所有回答(1)
0
private string GetMacAddress()
{
    const int MIN_MAC_ADDR_LENGTH = 12;
    string macAddress = string.Empty;
    long maxSpeed = -1;

    foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
    {
        string tempMac = nic.GetPhysicalAddress().ToString();
        if (nic.Speed > maxSpeed &&
            !string.IsNullOrEmpty(tempMac) &&
            tempMac.Length >= MIN_MAC_ADDR_LENGTH)
        {
            maxSpeed = nic.Speed;
            macAddress = tempMac;
        }
    }

    return macAddress;
}
深潭 | 园豆:187 (初学一级) | 2013-01-31 00:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册