如何识别网络接口是LAN还是Wifi或外部

时间:2012-08-01 06:33:27

标签: .net c#-4.0 network-programming network-protocols

我想区分我系统上可用的以太网。 无论是LAN,Wifi还是VMWare创建的东西。 I am only intrested for LAN

但是当我使用以下代码枚举时:

     NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
     foreach (NetworkInterface networkInterface in adapters)
     {

         Console.WriteLine("   {0}  ::: Interface Type {1} ::::ID {2}  \n", networkInterface.Name, networkInterface.NetworkInterfaceType, networkInterface.Id);
     }

现在我如何区分NetworkInterface.DescriptionNetworkInterface.NetworkInterfaceType无效。

还有其他方法吗?

enter image description here

2 个答案:

答案 0 :(得分:2)

查看使用WMI检索有关系统上网络适配器的更多详细信息。它会告诉您给定适配器是有线网络适配器还是无线适配器,以及它是否确实是“物理”网络适配器。

http://geekswithblogs.net/PsychoCoder/archive/2008/01/25/using_wmi_in_csharp.aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx

答案 1 :(得分:1)

要确定适配器是否是Wifi适配器,您可以使用root \ WMI命名空间中的MSNdis_PhysicalMediumType类。

不幸的是,VMware适配器在Windows中看起来好像是“真正的”物理适配器,并且具有MAC地址和IP地址等,因此很难区分它们。

如果你运行ncpa.cpl,你会在Windows中注意到它们看起来都和物理适配器一样。