From 507e1dd74d4fbefc3302d5fb23632c5ae0997ef1 Mon Sep 17 00:00:00 2001 From: d3agle Date: Thu, 11 Aug 2016 13:45:21 -0500 Subject: [PATCH] Fixed lan ip determination for virtual physical nics --- Client/Core/Helper/DevicesHelper.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Client/Core/Helper/DevicesHelper.cs b/Client/Core/Helper/DevicesHelper.cs index 58b19421..9c110a94 100644 --- a/Client/Core/Helper/DevicesHelper.cs +++ b/Client/Core/Helper/DevicesHelper.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Management; using System.Net.NetworkInformation; using System.Net.Sockets; @@ -143,17 +144,21 @@ namespace xClient.Core.Helper { foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) { - if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || - ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet && - ni.OperationalStatus == OperationalStatus.Up) + GatewayIPAddressInformation gatewayAddress = ni.GetIPProperties().GatewayAddresses.FirstOrDefault(); + if (gatewayAddress != null) //exclude virtual physical nic with no default gateway { - foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses) + if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || + ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet && + ni.OperationalStatus == OperationalStatus.Up) { - if (ip.Address.AddressFamily != AddressFamily.InterNetwork || - ip.AddressPreferredLifetime == UInt32.MaxValue) // exclude virtual network addresses - continue; + foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses) + { + if (ip.Address.AddressFamily != AddressFamily.InterNetwork || + ip.AddressPreferredLifetime == UInt32.MaxValue) // exclude virtual network addresses + continue; - return ip.Address.ToString(); + return ip.Address.ToString(); + } } } }