protected string GetClientIP()

        {
            string ip = null;
            string http_x_forwarded_for = Convert.ToString(Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
            string remote_addr = Convert.ToString(Request.ServerVariables["REMOTE_ADDR"]);
            if (string.IsNullOrEmpty(http_x_forwarded_for) ||
                (http_x_forwarded_for.IndexOf("UNKNOWN") > 0))
            {
                ip = remote_addr;
            }
            else if (http_x_forwarded_for.IndexOf(",") > 0)
            {
                ip = http_x_forwarded_for.Substring(1, http_x_forwarded_for.IndexOf(",") - 1);
            }
            else if (http_x_forwarded_for.IndexOf(";") > 0)
            {
                ip = http_x_forwarded_for.Substring(1, http_x_forwarded_for.IndexOf(";") - 1);
            }
            else
            {
                ip = http_x_forwarded_for;
            }
            return ip.Replace(" ", string.Empty);
        }
arrow
arrow
    全站熱搜

    level168 發表在 痞客邦 留言(0) 人氣()