Skip to content

Instantly share code, notes, and snippets.



Last active Dec 18, 2015
What would you like to do?
Un gist basé sur le code de
public static IPAddress GetIp(this System.Web.HttpRequest request)
string ipString;
if (string.IsNullOrEmpty(request.ServerVariables["HTTP_X_FORWARDED_FOR"]))
ipString = request.ServerVariables["REMOTE_ADDR"];
ipString = request
.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
IPAddress result;
if (!IPAddress.TryParse(ipString, out result))
result = IPAddress.None;
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment