- 使用NetworkInterface 类
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface adapter in adapters){
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
//
}
}
属性:
Description 获取接口的描述。Id 获取网络适配器的标识符。
IsReceiveOnly 获取 Boolean 值,该值指示网络接口是否设置为仅接收数据包。
Name 获取网络适配器的名称。
NetworkInterfaceType 获取接口类型。
OperationalStatus 获取网络连接的当前操作状态。
Speed 获取网络接口的速度。
- 使用WMI的方法
SELECT * FROM Win32_NetworkAdapter where PhysicalAdapter = TRUE and MACAddress>‘’ //只查询有MAC的物理网卡,不包含虚拟网卡
// ManagementObjectSearcher s = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration where IPenabled=true");
{
foreach (PropertyData pd in bb.Properties)
{
//
};
}
instance of Win32_NetworkAdapter
{
AdapterType = "Ethernet 802.3";
AdapterTypeId = 0;
Availability = 3;
Caption = "[00000007] Realtek PCIe GBE Family Controller";
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_NetworkAdapter";
Description = "Realtek PCIe GBE Family Controller";
DeviceID = "7";
GUID = "{318E3441-074A-413F-9A49-1896D9D3C388}";
Index = 7;
Installed = TRUE;
InterfaceIndex = 12;
MACAddress = "30:0E:D5:1B:65:08";
Manufacturer = "Realtek";
MaxNumberControlled = 0;
Name = "Realtek PCIe GBE Family Controller";
NetConnectionID = "本地连接";
NetConnectionStatus = 2;
NetEnabled = TRUE;
PhysicalAdapter = TRUE;
PNPDeviceID = "PCI\\VEN_10EC&DEV_8168&SUBSYS_0DA7105B&REV_07\\4&217507B3&0&00E3";
PowerManagementSupported = FALSE;
ProductName = "Realtek PCIe GBE Family Controller";
ServiceName = "RTL8167";
Speed = "100000000";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "C-HASEE-303";
TimeOfLastReset = "20170227151410.549655+480";
};
可以用 wbemtest.exe 程序查询WMI