I managed to get all the NetworkInterface's in the computer, then I reject the ipv6, the loopback and then I end up having 2 interfaces, one is the real Ethernet I want to use and one is the VPN I have open to work with some remote servers that I don't want to use.
Is there any way in C# to identify them? Both answer "InterNetwork" for the AddressFamily and both say "Ethernet" for the NetworkingInterfaceType
Any clue ?
List<IPAddress> localIPs = new List<IPAddress>();
var ifaces = NetworkInterface.GetAllNetworkInterfaces();
//I'm working on unity and it does not allow me to do .ToList().. for some reason.
List<NetworkInterface> IfacesList = new List<NetworkInterface>();
foreach (var i in ifaces)
IfacesList.Add(i);
var selected = IfacesList.FindAll(x => x.NetworkInterfaceType == NetworkInterfaceType.Ethernet);
if (selected.Count == 1)
{
var addresses = selected[0].GetIPProperties().UnicastAddresses;
//once again, cannot use .toList()
List<UnicastIPAddressInformation> addressesList = new List<UnicastIPAddressInformation>();
foreach (var address in addresses)
addressesList.Add(address);
var ip = addressesList.Find(x => x.Address.AddressFamily == AddressFamily.InterNetwork).Address;
return new IPEndPoint(ip, port);
}
else
{
//HERE I need to differentiate my IP from VPN IP
}
those are the two interfaces I end up having: