How to identify if the Network Interface is LAN or Wifi or External(如何识别网络接口是 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.Description
和 NetworkInterface.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 还是外部


基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01