NIC カードの IP アドレス、IP サブネット、ゲートウェイ、Mac、およびネットワーク カード名 (説明) を見つけるコードがあります。しかし問題は、PC に複数の NIC カードと WiFi があることです。そして、このプログラムでは 4 つの NIC カードではなく、1 つのプライマリしか表示されません。この問題をどのように解決できますか?
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);
}
}