1.添加程序集

2.引入命名空间

using System.Management;

 

3.方法

ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection nics = mc.GetInstances();
foreach (ManagementObject nic in nics)
{
if (Convert.ToBoolean(nic["ipEnabled"]) == true)
{
string mac = nic["MacAddress"].ToString();//Mac地址
string ip = (nic["IPAddress"] as String[])[0];//IP地址
string ipsubnet = (nic["IPSubnet"] as String[])[0];//子网掩码
string ipgateway = (nic["DefaultIPGateway"] as String[])[0];//默认网关
}
}

 

posted on 2015-02-05 11:50  努力实现目标  阅读(3873)  评论(1编辑  收藏  举报