绕过代理服务器,ASP IIS 上的网站

Bypass Proxy Server, ASP Website on IIS

我实际上已经在 IIS 上部署了我的 asp 网站并且一切正常。我已经阅读了一些关于如何绕过代理服务器的资料,但我仍然不确定如何去做。我想绕过网络上的代理服务器的原因是能够读取客户端的 ip 地址(代理后面的 ip 地址)。坦白说,我对这个话题了解不多..

我从 MSDN 上了解到,您可以将代码行添加到 Web.Config 文件中以绕过代理服务器。但我不确定要输入什么或如何使用这个 defaultproxy 标签。

Link

现在我只检索本地主机 127.0.0.1 或机器的网络外部 ip 地址,这不是我想要的..

任何人都可以指出正确的方向以获取代理后面的 ip 地址吗?请感谢任何帮助。谢谢..

我一直在尝试获取客户端 IP 地址的代码:

protected void getIP_Click(object sender, EventArgs e)
{
    String hostName = System.Net.Dns.GetHostName();
    String clientIpAddressHostName = System.Net.Dns.GetHostAddresses(hostName).GetValue(0).ToString();
    IP1.Text = clientIpAddressHostName;

    String clientIpAddress = HttpContext.Current.Request.ServerVariables["REMOTE_HOST"].ToString();
    IP2.Text = clientIpAddress;

    String ip = null;

    if (String.IsNullOrEmpty(HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]))
    {
        ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    }

    IP3.Text = ip;

    String ipNext = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
    IP4.Text = ipNext;

    //String ipNextNext = HttpContext.Current.Request.UserHostAddress;
    String ipNextNext = HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"].ToString();
    IP5.Text = ipNextNext;

    String last = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList.GetValue(0).ToString();
    IP6.Text = last;

    Label2.Text = getIPAdd();

    try
    {
        String externalIP;
        externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
        externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}")).Matches(externalIP)[0].ToString();
        Label1.Text = externalIP;
    }
    catch (Exception ex)
    {
        logManager log = new logManager();
        log.addLog("IP Add", "IP Add", ex);
    }
}

private String getIPAdd()
{
    System.Web.HttpContext context = System.Web.HttpContext.Current;
    string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

    if (!string.IsNullOrEmpty(ipAddress))
    {
        string[] addresses = ipAddress.Split(',');
        if (addresses.Length != 0)
        {
            return addresses[0];
        }
    }

    return context.Request.ServerVariables["REMOTE_ADDR"];
}

结果,

请求的详细信息:

我只是用它来获取客户端 IP 地址:

HttpContext.Current.Request.UserHostAddress

据我所知,您的代码中也有那个,但它被注释掉了。 它对我有用: