Dylan Jackson
Dylan Jackson

Reputation: 811

Using win32_NetworkAdapterSettings to query a specific NIC. C#

Im trying to get tcp/ip info and physical info from a NIC card. I have queries for both (from win_32 NetworkAdapter and win32_NetworkAdapterConfiguration) But i want to join them together so i can select a specific network card from a combobox and get both sets of info.

I have been told I can use win_32 NetworkAdaptersetting but Im pretty new to this stuff so I don't know how!! It must be in c#.

Upvotes: 1

Views: 1953

Answers (1)

Uros Calakovic
Uros Calakovic

Reputation:

Here is an example:

using System;
using System.Management;

namespace WMITest
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementObjectSearcher searcher = 
                new ManagementObjectSearcher(
                    "Select * From Win32_NetworkAdapter");

            foreach (ManagementObject adapter in searcher.Get())
            {
                Console.WriteLine(adapter["Name"]);

                foreach(ManagementObject configuration in
                    adapter.GetRelated("Win32_NetworkAdapterConfiguration"))
                {
                    Console.WriteLine(configuration["Caption"]);
                }

                Console.WriteLine();
            }
        }
    }
}

Upvotes: 2

Related Questions