摘要:添加对System.Management的引用
using System.Management;。。。//获取IP,子网掩码(subnet mask)和默认网关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]); } }。。。
如果还需要其他信息参考 Platform SDK: Windows Management Instrumentation...[
阅读全文]