How to identify if the Network Interface is LAN or Wifi or External

☆樱花仙子☆ 提交于 2019-12-02 06:24:58

问题


I want to differentiate between the Ethernets available on my system. Whether that's a LAN , Wifi or something created by VMWare. I am only intrested for LAN.

But when I am enumerating with following code:

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

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

Now how do I differentiate as NetworkInterface.Description and NetworkInterface.NetworkInterfaceType are not useful.

Any other ways around?


回答1:


Look at using WMI to retrieve more detailed information about network adapters on the system. It'll tell you whether or not a given adapter is a wired network adapter or wireless, and if it is indeed a 'physical' network adapter.

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




回答2:


To find out if the adapter is a Wifi adapter you can use the MSNdis_PhysicalMediumType class in the root\WMI namespace.

Unfortunately the VMware adapters appear to Windows as if they are "real" physical adapters and have a MAC address and IP address etc so it's hard to differentiate those.

You'll notice in Windows if you run ncpa.cpl they all appear the same as physical adapters.



来源:https://stackoverflow.com/questions/11753757/how-to-identify-if-the-network-interface-is-lan-or-wifi-or-external

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!