效果:
说明:获取本局域网的MAC地址(非本机的MAC地址)
代码:
/// <summary>
/// 获取网卡物理地址
/// </summary>
/// <returns></returns>
public static string getMAC()
{
string madAddr = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach (ManagementObject mo in moc2)
{ www.jbxue.com
if (Convert.ToBoolean(mo["IPEnabled"]) == true)
{
madAddr = mo["MacAddress"].ToString();
madAddr = madAddr.Replace(':', '-');
}
mo.Dispose();
}
return madAddr;
}