deleted
deleted

Reputation: 363

How to get multiple network interface cards data

I have code, which find my NIC card IP address, IP subnet, Gateway, Mac and network card name (description). But the problem is, I have multiple NIC cards and WiFi on my PC. And this program instead of 4 NIC cards shows me only one primary. How can solve this problem ?

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);
            }
        }

Upvotes: 0

Views: 1112

Answers (1)

L.B
L.B

Reputation: 116098

You just assign the last value of the loop to textBoxes like textBox3.Text = .....

either append to textBox3.Text += ... or use a combo box.

Upvotes: 3

Related Questions