2012-07-28 49 views
0

我有代碼,它找到我的NIC卡IP地址,IP子網,網關,Mac和網卡名稱(說明)。但問題是,我的電腦上有多個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); 
      } 
     } 
+0

任何人,請! – deleted 2012-07-28 17:29:14

+0

如果將查詢更改爲SELECT * FROM Win32_NetworkAdapterConfiguration,是否會獲得所有網絡適配器配置? – Hans 2012-07-28 17:31:57

+0

@Hans,在簡單的列表中,我得到所有卡! – deleted 2012-07-28 17:33:18

回答

3

您只需將最後一個循環值賦給文本框,如textBox3.Text = ....

可以追加到textBox3.Text += ...或使用組合框。