通过C#获取网络接口类型

时间:2017-02-08 07:27:25

标签: c# networking

我通过C#查询计算机的网络接口如下:

var s = Symbol('foo');
console.log(s.toString()); //"Symbol(foo)"
var sS = Symbol(s); // <- thorws error
var sF = Symbol.for(s); // <- thorws error
console.log(s, sA);

返回包含网络接口的列表。问题是它包含接口的名称(Broadcom Family ...)。但我的用户不明白这是什么类型的接口(以太网,wifi,...)。是否有可能弄清楚这是什么类型的网络接口?我该怎么做?

1 个答案:

答案 0 :(得分:3)

不确定您使用什么来获取所有网络接口,但在.NET中我们class System.Net.NetworkInformation中有NetworkInterface namespace

您可以使用方法NetworkInterface.GetAllNetworkInterfaces()获取所有接口。

然后,要了解您获得的界面类型,可以查看NetworkInterfaceType属性。它是enum所以为了你的目的,你可以这样做:

foreach (NetworkInterface netInterface in NetworkInterface.GetAllNetworkInterfaces())
{
    if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 
        || netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
    {
        //your logic here
    }
}