简体   繁体   English

如何确定我的计算机正在使用哪个网络适配器?

[英]How do I determine which network adapter my computer is using?

I am using Pcat.Net. 我正在使用Pcat.Net。 How do I determine which network adapter my computer is using C#, .Net, Pcat.net? 如何确定计算机使用C#、. Net,Pcat.net的网络适配器? GetMacAddress() extension method returns just the mac address of the network adapter, LivePacketDevice.AllLocalMachine also does not return information that can identify if the network adapter is being used by my computer. GetMacAddress()扩展方法仅返回网络适配器的mac地址,LivePacketDevice.AllLocalMachine也不返回可以识别计算机是否正在使用网络适配器的信息。

You can try using NetworkInterface.GetAllNetworkInterfaces Method. 您可以尝试使用NetworkInterface.GetAllNetworkInterfaces方法。 You can get more details from below link: 您可以从以下链接获取更多详细信息:

https://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces(v=vs.110).aspx https://msdn.microsoft.com/zh-cn/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces(v=vs.110).aspx

I used the following code to determine if my computer was connected to the internet. 我使用以下代码来确定我的计算机是否已连接到Internet。

var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
var connectedNetworkInterfaces = networkInterfaces.Where(
counter=> counter.OperationalStatus == OperationalStatus.Up && 
(counter.NetworkInterfaceType != NetworkInterfaceType.Loopback || counter.NetworkInterfaceType != NetworkInterfaceType.Tunnel));
if(connectedNetworkInterfaces.Count() <1)
{
    throw new Exception("The computer does not seem to be connected to the internet.");
}
var connectedNetworkInterface = connectedNetworkInterfaces.First();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM