简体   繁体   中英

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

I am using Pcat.Net. How do I determine which network adapter my computer is using 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.

You can try using NetworkInterface.GetAllNetworkInterfaces Method. You can get more details from below link:

https://msdn.microsoft.com/en-us/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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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