winform C# 获取区分物理网卡、虚拟网卡及无线网卡
摘要:=空)35{36//区分PnpInstanceID37//如果前面的PCI是这台机器的真实网卡38//MediaSubType是01,它是一个普通网卡,02是一个无线网卡。39stringPnpInstanceID=rk.GetValue.ToString();40intfMediaSubType=Convert.ToInt32;41if43fCardType=“物理网卡”;44elseif45fCardType=“虚拟网卡”;46elseif47fCardType=“无线网卡”;48}49#endregion 50#region“网卡信息”51Console。WriteLine;52Console.WriteLine;53Console.WriteLine;54Console.WriteLine;//获取网络适配器55Console.WriteLine//的标识符获取网络适配器56Console.WriteLine//的名称获取接口57Console.WriteLine的描述//获取接口类型58Console.Write Line//获取一个布尔值,该值指示网络接口是否设置为仅接收数据包。
02 | using System.Collections.Generic; |
05 | using System.Net.NetworkInformation; |
06 | using System.Net.Sockets; |
10 | /// <SUMMARY></SUMMARY> |
11 | /// 标题:区分本地网卡、虚拟网卡及无线网卡 |
14 | /// 描述:测试环境 VS2008 + XP |
15 | /// <SUMMARY></SUMMARY> |
18 | static void Main( string [] args) |
20 | ShowNetworkInterfaceMessage(); |
22 | /// <SUMMARY></SUMMARY> |
24 | /// <SUMMARY></SUMMARY> |
25 | public static void ShowNetworkInterfaceMessage() |
27 | NetworkInterface[] fNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); |
28 | foreach (NetworkInterface adapter in fNetworkInterfaces) |
31 | string fCardType = "未知网卡" ; |
32 | string fRegistryKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\" + adapter.Id + "\\Connection" ; |
33 | RegistryKey rk = Registry.LocalMachine.OpenSubKey(fRegistryKey, false ); |
37 | // 如果前面有 PCI 就是本机的真实网卡 |
38 | // MediaSubType 为 01 则是常见网卡,02为无线网卡。 |
39 | string fPnpInstanceID = rk.GetValue( "PnpInstanceID" , "" ).ToString(); |
40 | int fMediaSubType = Convert.ToInt32(rk.GetValue( "MediaSubType" , 0)); |
41 | if (fPnpInstanceID.Length > 3 && |
42 | fPnpInstanceID.Substring(0, 3) == "PCI" ) |
44 | else if (fMediaSubType == 1) |
46 | else if (fMediaSubType == 2) |
51 | Console.WriteLine( "-----------------------------------------------------------" ); |
52 | Console.WriteLine( "-- " + fCardType); |
53 | Console.WriteLine( "-----------------------------------------------------------" ); |
54 | Console.WriteLine( "Id .................. : {0}" , adapter.Id); // 获取网络适配器的标识符 |
55 | Console.WriteLine( "Name ................ : {0}" , adapter.Name); // 获取网络适配器的名称 |
56 | Console.WriteLine( "Description ......... : {0}" , adapter.Description); // 获取接口的描述 |
57 | Console.WriteLine( "Interface type ...... : {0}" , adapter.NetworkInterfaceType); // 获取接口类型 |
58 | Console.WriteLine( "Is receive only...... : {0}" , adapter.IsReceiveOnly); // 获取 Boolean 值,该值指示网络接口是否设置为仅接收数据包。 |
59 | Console.WriteLine( "Multicast............ : {0}" , adapter.SupportsMulticast); // 获取 Boolean 值,该值指示是否启用网络接口以接收多路广播数据包。 |
60 | Console.WriteLine( "Speed ............... : {0}" , adapter.Speed); // 网络接口的速度 |
61 | Console.WriteLine( "Physical Address .... : {0}" , adapter.GetPhysicalAddress().ToString()); // MAC 地址 |
62 | IPInterfaceProperties fIPInterfaceProperties = adapter.GetIPProperties(); |
63 | UnicastIPAddressInformationCollection UnicastIPAddressInformationCollection = fIPInterfaceProperties.UnicastAddresses; |
64 | foreach (UnicastIPAddressInformation UnicastIPAddressInformation in UnicastIPAddressInformationCollection) |
66 | if (UnicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork) |
67 | Console.WriteLine( "Ip Address .......... : {0}" , UnicastIPAddressInformation.Address); // Ip 地址 |
原文地址:http://blog.csdn.net/sabty/archive/2009/08/03/4404488.aspx
免责声明:文章转载自《winform C# 获取区分物理网卡、虚拟网卡及无线网卡》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇vmware已经全面支持open-vm-tools图片的懒加载和预加载下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=