我有代码,可以找到我的 NIC 卡 IP 地址、IP 子网、网关、Mac 和网卡名称(描述)。但问题是,我的 PC 上有多个 NIC 卡和 WiFi。而这个程序而不是 4 个 NIC 卡只显示了一个主卡。如何解决这个问题?
public void NIC_data()
{
ManagementObjectSearcher query = new
ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
ManagementObjectCollection queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
string[] addresses = (string[])mo["IPAddress"];
string[] subnets = (string[])mo["IPSubnet"];
string[] defaultgateways = (string[])mo["DefaultIPGateway"];
textBox1.Text = string.Format("Network Card: {0}", mo["Description"]);
textBox2.Text = string.Format(" MAC Address: {0}", mo["MACAddress"]);
foreach (string ipaddress in addresses)
{
textBox3.Text = string.Format(" IP Address: {0}", ipaddress);
}
foreach (string subnet in subnets)
{
textBox4.Text = string.Format(" Subnet Mask: {0}", subnet);
}
foreach (string defaultgateway in defaultgateways)
{
textBox5.Text = string.Format(" Gateway: {0}", defaultgateway);
}
}