1. 添加程序集
2. 引入命名空间
using system.management;
3. 方法
1
2
3
4
5
6
7
8
9
10
11
12
|
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]; //默认网关
}
}
|
以上这篇winform c#获得mac地址,ip地址,子网掩码,默认网关的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。