zoukankan      html  css  js  c++  java
  • 获取客户端IP

     public static string GetWebClientIp()
            {
    
                string userIP = "未获取用户IP";
    
                try
                {
                    if (System.Web.HttpContext.Current == null
                        || System.Web.HttpContext.Current.Request == null
                        || System.Web.HttpContext.Current.Request.ServerVariables == null)
                        return "";
    
                    string CustomerIP = "";
    
                    //CDN加速后取到的IP simone 090805
                    CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
                    if (!string.IsNullOrEmpty(CustomerIP))
                    {
                        return CustomerIP;
                    }
    
                    CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    
    
                    if (!String.IsNullOrEmpty(CustomerIP))
                        return CustomerIP;
    
                    if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
                    {
                        CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                        if (CustomerIP == null)
                            CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    }
                    else
                    {
                        CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    
                    }
    
                    if (string.Compare(CustomerIP, "unknown", true) == 0)
                        return System.Web.HttpContext.Current.Request.UserHostAddress;
                    return CustomerIP;
                }
                catch
                {
    
                }
    
                return userIP;
    
            }
    

      

  • 相关阅读:
    GUI 之 JDialog弹窗
    GUI Swing 之 JFrame窗体
    GUI 键盘监听事件
    GUI 窗口监听事件
    GUI 鼠标监听事件,模拟画图工具
    shell编程
    Ubuntu20.04 Linux初识
    rlwrap的使用
    5个相见恨晚的Linux命令,每一个都非常实用
    Bash初识与常用命令
  • 原文地址:https://www.cnblogs.com/xffy1028/p/3935764.html
Copyright © 2011-2022 走看看