1:NetworkInterface 类:
该类位于 System.Net.NetworkInformation 命名空间
该类可以方便的检测本机有多少个网卡(网络适配器),网卡信息,哪些网络连接可用等。
2:常用方法和属性:
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); |
Console.WriteLine( "适配器个数:" + adapters.Length);
|
foreach (NetworkInterface adapter in adapters)
|
Console.WriteLine( "描述:" + adapter.Description);
|
Console.WriteLine( "标识符:" + adapter.Id);
|
Console.WriteLine( "名称:" + adapter.Name);
|
Console.WriteLine( "类型:" + adapter.NetworkInterfaceType);
|
Console.WriteLine( "速度:" + adapter.Speed * 0.001 * 0.001 + "M" );
|
Console.WriteLine( "操作状态:" + adapter.OperationalStatus);
|
Console.WriteLine( "MAC 地址:" + adapter.GetPhysicalAddress());
|
PhysicalAddress pa = adapter.GetPhysicalAddress();
|
byte [] bytes = pa.GetAddressBytes();
|
StringBuilder sb = new StringBuilder();
|
for ( int i = 0; i < bytes.Length; i++)
|
sb.Append(bytes[i].ToString( "X2" ));
|
if (i != bytes.Length - 1)
|
Console.WriteLine( "MAC 地址:" + sb);
|
3:板载网卡:
描述:Realtek PCIe GBE Family Controller
标识符:{AEDA3FF2-F692-4F18-8708-AC7FBBAEC6E2}
名称:本地连接
类型:Ethernet
速度:100M
操作状态:Up
MAC 地址:B8AC6F539CE9
MAC 地址:B8-AC-6F-53-9C-E9
4:无线网卡:
描述:Atheros AR9285 Wireless Network Adapter
标识符:{63361D79-3B9B-4680-91FA-DD556D5E01FF}
名称:无线网络连接
类型:Wireless80211
速度:150M
操作状态:Down
MAC 地址:0017C4EBF741
MAC 地址:00-17-C4-EB-F7-41