Skip to content

Commit

Permalink
Merge pull request quasar#505 from d3agle/master
Browse files Browse the repository at this point in the history
Fixed quasar#504 - Show all found LAN IP addresses
  • Loading branch information
MaxXor authored Aug 11, 2016
2 parents 2a1bbf6 + 507e1dd commit 702d0e2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions Client/Core/Helper/DevicesHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Management;
using System.Net.NetworkInformation;
using System.Net.Sockets;
Expand Down Expand Up @@ -143,17 +144,21 @@ public static string GetLanIp()
{
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;

return ip.Address.ToString();
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();
}
}
}
}
Expand Down

0 comments on commit 702d0e2

Please sign in to comment.