public void GetPhysicsNetworkAdapterInfo()
{
ManagementObjectSearcher mos = new ManagementObjectSearcher(@"\\.\ROOT\StandardCimv2", "SELECT * FROM MSFT_NetAdapter WHERE Virtual=False");
ManagementObjectCollection moc = mos.Get();
foreach (ManagementObject mo in moc)
{
string driverDescription = mo["DriverDescription"]?.ToString();
uint interfaceType = Convert.ToUInt32(mo["InterfaceType"] ?? 0);
string macAdddr = mo["PermanentAddress"]?.ToString();
Console.WriteLine("---------------------------------------");
Console.WriteLine($"DriverDescription:{driverDescription}");
Console.WriteLine($"MacAddr:{macAdddr}");
Console.WriteLine($"InterfaceType:{interfaceType}");
}
}
MSFT_NetAdapter所有成员:
MSFT_NetAdapter class (Windows) | Microsoft Docs
InterfaceType(可用于判断网卡为有线或无线):
NetworkInterfaceType Enum (System.Net.NetworkInformation) | Microsoft Docs