C#或取网卡地址

static string GetMAC()
{
    using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
    {
        ManagementObjectCollection moc = mc.GetInstances();
        foreach (ManagementObject mo in moc)
        {
            if ((bool)mo["IPEnabled"])
                return mo["MacAddress"].ToString();
        }
    }

    return null;
}

 需要添加 System.Management.dll 的引用

你可能感兴趣的:(C++,c,C#)