winform C#获得Mac地址,IP地址,子网掩码,默认网关的实例
时间:2021-03-12 09:54:57|栏目:.NET代码|点击: 次
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];//默认网关 } }
上一篇:浅谈类型转换操作符is/as
栏 目:.NET代码
下一篇:asp.net GridView控件中模板列CheckBox全选、反选、取消
本文标题:winform C#获得Mac地址,IP地址,子网掩码,默认网关的实例
本文地址:http://www.codeinn.net/misctech/79254.html