winform C#得到Mac地址,IP地址,子網掩碼,默認網關

1.添加程序集code

2.引入命名空間blog

using System.Management;

 

3.方法ip

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];//默認網關
}
}string

相關文章
相關標籤/搜索