Fixed lan ip determination for virtual physical nics

This commit is contained in:
d3agle 2016-08-11 13:45:21 -05:00
parent d291490181
commit 507e1dd74d
1 changed files with 13 additions and 8 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Management;
using System.Net.NetworkInformation;
using System.Net.Sockets;
@ -142,6 +143,9 @@ namespace xClient.Core.Helper
public static string GetLanIp()
{
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
GatewayIPAddressInformation gatewayAddress = ni.GetIPProperties().GatewayAddresses.FirstOrDefault();
if (gatewayAddress != null) //exclude virtual physical nic with no default gateway
{
if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet &&
@ -157,6 +161,7 @@ namespace xClient.Core.Helper
}
}
}
}
return "-";
}