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

How to identify if the Network Interface is LAN or Wifi or External(如何识别网络接口是 LAN 或 Wifi 还是外部)

本文介绍了如何识别网络接口是 LAN 或 Wifi 还是外部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想区分我系统上可用的以太网.无论是 LAN 、 Wifi 还是由 VMWare 创建的东西.我只对局域网感兴趣.

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}  
", networkInterface.Name, networkInterface.NetworkInterfaceType, networkInterface.Id);
     }

现在我如何区分 NetworkInterface.DescriptionNetworkInterface.NetworkInterfaceType 没用.

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

还有其他方法吗?

推荐答案

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

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

这篇关于如何识别网络接口是 LAN 或 Wifi 还是外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何识别网络接口是 LAN 或 Wifi 还是外部

基础教程推荐