zoukankan      html  css  js  c++  java
  • 获取IP地址

         /// <summary>
            /// 获得客户端IP地址,如果客户端使用代理服务器,并且代理服务器在HTTP Header中包含相关信息,则将返回用户真实IP地址
            /// </summary>
            public static string IP
            {
                get
                {
                    string ipStr = "";
                    try
                    {
                        if (HttpContext.Current.Request.ServerVariables["HTTP_X_REAL_IP"] != null)
                        {
                            ipStr = HttpContext.Current.Request.ServerVariables["HTTP_X_REAL_IP"].ToString();
                        }
                        else if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
                        {
                            ipStr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
                        }
                        else
                        {
                            ipStr = HttpContext.Current.Request.UserHostAddress;
                        }
                    }
                    catch { }
                    return ipStr;
                }
            }
  • 相关阅读:
    set用法
    01分数规划
    unique && stl的全排列
    lower_bound() && upper_bound()
    spfa判负环
    倍增求LCA
    数据生成c++程序模板
    samba
    vsftp快速配置
    grub丢失的修复
  • 原文地址:https://www.cnblogs.com/zy-theone/p/9885468.html
Copyright © 2011-2022 走看看