|
|
|
@ -53,19 +53,23 @@ namespace ZeroLevel.Network
|
|
|
|
|
return port;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IPAddress GetNonLoopbackAddress()
|
|
|
|
|
public static IPAddress GetNonLoopbackAddress(bool ignore_virtual_devices = true, bool ignore_docker_devices = true)
|
|
|
|
|
{
|
|
|
|
|
if (NetworkInterface.GetIsNetworkAvailable())
|
|
|
|
|
{
|
|
|
|
|
foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces())
|
|
|
|
|
{
|
|
|
|
|
if (adapter.Description.IndexOf("VirtualBox", StringComparison.OrdinalIgnoreCase) >= 0)
|
|
|
|
|
if (adapter.OperationalStatus == OperationalStatus.Up)
|
|
|
|
|
{
|
|
|
|
|
if (ignore_virtual_devices && (adapter.Description.IndexOf("Virtual", StringComparison.OrdinalIgnoreCase) >= 0 || adapter.Name.IndexOf("Virtual", StringComparison.OrdinalIgnoreCase) >= 0))
|
|
|
|
|
continue;
|
|
|
|
|
if (ignore_docker_devices && (adapter.Description.IndexOf("Docker", StringComparison.OrdinalIgnoreCase) >= 0 || adapter.Name.IndexOf("Docker", StringComparison.OrdinalIgnoreCase) >= 0))
|
|
|
|
|
continue;
|
|
|
|
|
if (adapter.NetworkInterfaceType != NetworkInterfaceType.Ethernet)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (UnicastIPAddressInformation address in adapter.GetIPProperties().UnicastAddresses)
|
|
|
|
|
{
|
|
|
|
|
if (address.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
|
|
|
|
if (address.Address.AddressFamily == AddressFamily.InterNetwork)
|
|
|
|
|
{
|
|
|
|
|
if (!IPAddress.IsLoopback(address.Address))
|
|
|
|
|
{
|
|
|
|
@ -75,6 +79,7 @@ namespace ZeroLevel.Network
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|