Editor is used: visual studio 2010
1.c # introduced wmi way.
In new projects need to introduce System.Management
2. Examples of Win32_NetworkAdapterConfiguration
ManagementClass mc; ManagementObjectCollection moc; mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); moc = mc.GetInstances();
3. Obtain an IP address using the enhanced circulation
List<string> list = new List<string>(); List<string[]> lists = new List<string[]>(); foreach(ManagementObject mo in moc){ if((bool)mo.GetPropertyValue("IPEnabled")){ list.Add((string)mo.GetPropertyValue("Description")); lists.Add((string[])mo.GetPropertyValue("IPAddress")); } } foreach(string s in list){ Console.WriteLine(s); } foreach(string[] ss in lists){ foreach(string s in ss){ Console.WriteLine(s); } }