/// <summary>
/// 获得当前机器的活动中Mac地址,若无联网则返回空""
/// </summary>
/// <returns>mac地址,例如:18:03:73:AE:38:0D</returns>
public static string GetActivatedAdaptorMacAddress()
{
string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (mo["IPEnabled"].ToString() == "True")
{
mac = mo["MacAddress"].ToString();
}
}
return mac;
}
网友评论