diff --git a/Zero-K.info/Controllers/ForumController.cs b/Zero-K.info/Controllers/ForumController.cs index 148301e7a2..a31a97a150 100644 --- a/Zero-K.info/Controllers/ForumController.cs +++ b/Zero-K.info/Controllers/ForumController.cs @@ -244,7 +244,7 @@ public ActionResult SubmitPost( forumPostID == null && string.IsNullOrWhiteSpace(title)) return Content("Cannot post new thread with blank title"); if (string.IsNullOrWhiteSpace(text)) return Content("Please type some text :)"); - var penalty = Punishment.GetActivePunishment(Global.AccountID, Request.ServerVariables["REMOTE_ADDR"], 0, x => x.BanForum); + var penalty = Punishment.GetActivePunishment(Global.AccountID, MvcApplication.GetUserIP(Request), 0, x => x.BanForum); if (penalty != null) { return diff --git a/Zero-K.info/Global.asax.cs b/Zero-K.info/Global.asax.cs index 5632c73d2c..33e96aac55 100644 --- a/Zero-K.info/Global.asax.cs +++ b/Zero-K.info/Global.asax.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Net; using System.Web; using System.Web.Mvc; using System.Web.Optimization; @@ -102,8 +103,16 @@ protected void Application_Start() private string GetUserIP() { - var ip = Context.Request.ServerVariables["REMOTE_ADDR"]; - return ip; + return GetUserIP(new HttpRequestWrapper(Context.Request)); + } + + public static string GetUserIP(HttpRequestBase request) + { + string hostname = request.ServerVariables["REMOTE_HOST"]; + IPAddress[] ipv4s = Array.FindAll(Dns.GetHostEntry(hostname).AddressList, + a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); + if (ipv4s.Length > 0) return ipv4s[0].ToString(); + return request.ServerVariables["REMOTE_ADDR"]; } private void MvcApplication_Error(object sender, EventArgs e)