From 7f3720c8cab28d5055d1c931ab046a199a59536f Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Thu, 21 May 2015 16:22:53 +0200 Subject: [PATCH] More GeoIP debugging --- Logic/Support/General.cs | 20 ++++++++++++++++++++ Site5/Pages/v5/Public/Signup.aspx.cs | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Logic/Support/General.cs b/Logic/Support/General.cs index 14a707b8..d65f63e9 100644 --- a/Logic/Support/General.cs +++ b/Logic/Support/General.cs @@ -36,6 +36,7 @@ namespace Swarmops.Logic.Support return result.ToString(); } + // ReSharper disable once InconsistentNaming -- IPAddress is the canonical writing public static string GetRemoteIPAddressChain() { string forwardedIps = @@ -54,5 +55,24 @@ namespace Swarmops.Logic.Support return result; } + + // ReSharper disable once InconsistentNaming -- IPAddress is the canonical writing + public static string GetMostLikelyRemoteIPAddress() + { + // All of this can be faked trivially by the client, so you can't rely on it for any kind of security. + + string forwardedIps = + HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; + + string directIp = + HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; + + if (!string.IsNullOrEmpty (forwardedIps)) + { + return forwardedIps.Split (',').Last(); + } + + return directIp; + } } } diff --git a/Site5/Pages/v5/Public/Signup.aspx.cs b/Site5/Pages/v5/Public/Signup.aspx.cs index 04af4b7f..52f9663e 100644 --- a/Site5/Pages/v5/Public/Signup.aspx.cs +++ b/Site5/Pages/v5/Public/Signup.aspx.cs @@ -296,7 +296,7 @@ namespace Swarmops.Frontend.Pages.Public try { - string ipAddress = HttpContext.Current.Request.UserHostAddress; + string ipAddress = Logic.Support.SupportFunctions.GetMostLikelyRemoteIPAddress(); NGeoIP.Request request = new Request() {