怎样穿过代理服务器取远程用户真实IP地址老是取到外国的,肯定是有人用代理来的请问有什么方法吗

解决方案 »

  1.   

    private string getIp()
    {/*穿过代理服务器取远程用户真实IP地址:*/
    if(Request.ServerVariables["HTTP_VIA"]!=null)
    return Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
    else
    return Request.ServerVariables["REMOTE_ADDR"].ToString();
    }
    Label2.Text =getIp();
    HttpBrowserCapabilities bc = new HttpBrowserCapabilities();
    bc = Request.Browser;
    string xitong ="你的操作系统为";
    Label3.Text=xitong+bc.Platform + " 浏览器类型:" + bc.Type;
      

  2.   

    下午刚好用到
    private string Ip()
    if(Request.ServerVariables["HTTP_VIA"]!=null)
    {
       return Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
    }
    else
    {
      return Request.ServerVariables["REMOTE_ADDR"].ToString();
    }
    Label1.Text =Ip();
      

  3.   

    public static string GetRealIP()
    {
    string ip;
    try
    {
    HttpRequest request = HttpContext.Current.Request;if (request.ServerVariables["HTTP_VIA"] != null)
    {
    ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
    }
    else
    {
    ip = request.UserHostAddress;
    }
    }
    catch (Exception e)
    {
    throw e;
    }return ip;
    }
    真实IPpublic static string GetViaIP()
    {
    string viaIp = null;try
    {
    HttpRequest request = HttpContext.Current.Request;if (request.ServerVariables["HTTP_VIA"] != null)
    {
    viaIp = request.UserHostAddress;
    }}
    catch (Exception e)
    {throw e;
    }return viaIp;
    得代理IP如果多级代理不知能不能成功