public string GetMacString()
{
string resMac ="";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach(ManagementObject mo in moc2)
{
if((bool) mo ["IPEnabled"] == true)
{
resMac= mo["MacAddress"].ToString();
mo.Dispose();
return resMac;
}
}
return resMac;
}
注意:需要引用System.Management ;
时间: 2024-12-22 04:37:52