diff --git a/DnsServerCore/Extensions.cs b/DnsServerCore/Extensions.cs index d1d3a9f3..e5017d20 100644 --- a/DnsServerCore/Extensions.cs +++ b/DnsServerCore/Extensions.cs @@ -32,7 +32,7 @@ namespace DnsServerCore { readonly static string[] HTTP_METHODS = new string[] { "GET", "POST" }; - public static IPEndPoint GetRemoteEndPoint(this HttpContext context, string realIpHeaderName) + public static IPEndPoint GetRemoteEndPoint(this HttpContext context, string realIpHeaderName = null, bool readRealIpHeaderForPrivateIpOnly = true) { try { @@ -43,14 +43,12 @@ namespace DnsServerCore if (remoteIP.IsIPv4MappedToIPv6) remoteIP = remoteIP.MapToIPv4(); - if (!string.IsNullOrEmpty(realIpHeaderName) && NetUtilities.IsPrivateIP(remoteIP)) + if (!string.IsNullOrEmpty(realIpHeaderName) && (!readRealIpHeaderForPrivateIpOnly || NetUtilities.IsPrivateIP(remoteIP))) { + //get the real IP address of the requesting client from X-Real-IP header set in nginx proxy_pass block string xRealIp = context.Request.Headers[realIpHeaderName]; if (IPAddress.TryParse(xRealIp, out IPAddress address)) - { - //get the real IP address of the requesting client from X-Real-IP header set in nginx proxy_pass block return new IPEndPoint(address, 0); - } } return new IPEndPoint(remoteIP, context.Connection.RemotePort);