您的位置:首页 - 教程 - C# - 正文
C#获取本机mac地址

添加System.Management的引用,

using System.Management;

string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc=mc.GetInstances();

foreach(ManagementObject mo in moc)
{
    if ((bool)mo["IPEnabled"])
    {
        mac = mo["MacAddress"].ToString();
    }
}

评论: