AI智能
改变未来

c# 区分虚拟网卡 获取真实网卡信息 判断网卡有线或无线

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

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » c# 区分虚拟网卡 获取真实网卡信息 判断网卡有线或无线