Skip to content

Commit

Permalink
fix: remove obtaining IPv4
Browse files Browse the repository at this point in the history
  • Loading branch information
romanov.ah committed Aug 26, 2024
1 parent 2a4f324 commit c4171a5
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions Vostok.Commons.Environment/EnvironmentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal static class EnvironmentInfo

/// <summary>
/// Returns the IPv4 through which the application is accessible on the hosting network.
/// This value is obtained once when the application starts and is cached for subsequent calls.
/// </summary>
public static string ServiceDiscoveryIPv4 => serviceDiscoveryIPv4.Value;

Expand Down Expand Up @@ -205,28 +206,7 @@ private static string ObtainServiceDiscoveryIPv4()
{
try
{
var localIpV4 = System.Environment.GetEnvironmentVariable(LocalServiceDiscoveryIPv4Variable);
if (localIpV4 != null)
return localIpV4;

var dnsAddresses = Dns.GetHostAddresses(ObtainHostname());

var interfaceAddresses = NetworkInterface
.GetAllNetworkInterfaces()
.Where(iface => iface.OperationalStatus == OperationalStatus.Up)
.Where(iface => iface.GetIPProperties().GatewayAddresses.Any(info => !info.Address.Equals(IPAddress.Any)))
.SelectMany(iface => iface.GetIPProperties().UnicastAddresses)
.Select(info => info.Address)
.ToList();

var address = dnsAddresses
.Where(address => address.AddressFamily == AddressFamily.InterNetwork)
.Where(address => !IPAddress.IsLoopback(address))
.Where(address => interfaceAddresses.Contains(address))
.Select(address => address.ToString())
.FirstOrDefault();

return address;
return System.Environment.GetEnvironmentVariable(LocalServiceDiscoveryIPv4Variable);
}
catch
{
Expand Down

0 comments on commit c4171a5

Please sign in to comment.