获取用户真实ip
public static string getrealip()
{
string result = system.web.httpcontext.current.request.headers["cdn-src-ip"];
if(string.isnullorempty(result)){
result = system.web.httpcontext.current.request.headers["http_x_forwarded_for"];
}
if(string.isnullorempty(result)){
result = system.web.httpcontext.current.request.headers["http_via"];
}
if(string.isnullorempty(result)){
result = system.web.httpcontext.current.request.headers["remote_addr"];
}
if(string.isnullorempty(result)||!isip(result)){
result = "127.0.0.1";
}
return result;
}
/// <summary>
///是否为ip
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public static bool isip(string ip)
{
return regex.ismatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$");
}
上一篇: 动图:江湖牛人与运气不好的倒霉蛋图片
下一篇: 逗比图片,寂寞的人总是如此的相似