0

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.

Ajit Goel
  • 4,180
  • 7
  • 59
  • 107

2 Answers2

1

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

Aman Sahni
  • 212
  • 1
  • 8
  • Happy to help you :) – Aman Sahni Jul 18 '17 at 03:54
  • thanks @Aman sahni, I used networkInterfaces.Where(counter=> counter.OperationalStatus == OperationalStatus.Up && (counter.NetworkInterfaceType != NetworkInterfaceType.Loopback || counter.NetworkInterfaceType != NetworkInterfaceType.Tunnel)).First(). Not sure if there is a better way to find out the network adapter that my computer is using. – Ajit Goel Jul 18 '17 at 04:07
0

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();
Ajit Goel
  • 4,180
  • 7
  • 59
  • 107