asp.net 获取客户端真实Ip

来源:互联网 发布:擦枪字幕组怎么样知乎 编辑:程序博客网 时间:2024/05/16 18:01
private string GetIp()
        {
            string ip = "";
            if (!string.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]))
            {
                ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].Split(new char[] {','})[0];
                // Return real client IP. 
            }
            if (string.IsNullOrEmpty(ip))
            {
                ip = Context.Request.ServerVariables["REMOTE_ADDR"].ToString();
            }
            return ip;
        }

不能排除在使用欺骗代理和伪造ip情况下获取不到真实Ip

0 0