利用WMI 获取IP信息

时间:2013-06-07 08:09:14
【文件属性】:

文件名称:利用WMI 获取IP信息

文件大小:589B

文件格式:RAR

更新时间:2013-06-07 08:09:14

WMI IP

利用WMI 获取IP信 using System; using System.Collections.Generic; using System.Text; using System.Management; namespace NetProgram { class WMICardGrab { public static void Main() { //1。 ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled='TRUE'"); //2。 ManagementObjectCollection queryCollection = query.Get(); foreach (ManagementObject mo in queryCollection) { string[] addresses = (string[])mo["IPAddress"]; string[] subnets = (string[])mo["IPSubnet"]; string[] defaultgateways = (string[])mo["DefaultIPGateway"]; Console.WriteLine("Network Card:{0}", mo["Description"]); Console.WriteLine(" MAC Adress:{0}", mo["MacAddress"]); foreach (string ipaddress in addresses) { Console.WriteLine(" IP Address:{0}", ipaddress); } foreach (string subnet in subnets) { Console.WriteLine(" Subnet Mask:{0}", subnet); } foreach (string defaultgageway in defaultgateways) { Console.WriteLine(" Gateway:{0}", defaultgageway); } } } } }


【文件预览】:
WMICardGrab.txt

网友评论