首先找到资源管理器里的引用,右击添加引用:System.Management;
- using System;
- using System.Management;
-
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
- ManagementObjectCollection nics = mc.GetInstances();
- foreach (ManagementObject nic in nics)
- {
- if (Convert.ToBoolean(nic["ipEnabled"]) == true)
- {
- Console.WriteLine((nic["IPAddress"] as String[])[0]);
- Console.WriteLine((nic["IPSubnet"] as String[])[0]);
- Console.WriteLine((nic["DefaultIPGateway"] as String[])[0]);
- }
- }
- }
- }
- }
本文转自 陈敬(Cathy) 博客园博客,原文链接:http://www.cnblogs.com/janes/archive/2008/10/19/1314439.html
,如需转载请自行联系原作者