需要添加引用:System.Management
public static string GetMacAddress()
{
string macAddress = "";
using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
{
ManagementObjectCollection moc2 = mc.GetInstances();
foreach (ManagementObject mo in moc2)
{
if ((bool)mo["IPEnabled"] == true)
macAddress = mo["MacAddress"].ToString();
mo.Dispose();
}
}
return macAddress;
}