【发布时间】:2018-01-13 05:47:47
【问题描述】:
我实际上已经在 IIS 上部署了我的 ASP 网站,并且一切正常。我已经阅读了一些关于如何绕过代理服务器的文章,但我仍然不确定如何去做。我想绕过网络上的代理服务器的原因是能够读取客户端的IP地址(代理后面的IP地址)。坦率地说,我对这个话题了解不多..
我从 MSDN 中了解到,您可以在 Web.Config 文件中添加几行代码以绕过代理服务器。但我不确定要输入什么或如何使用这个 defaultproxy 标签。
现在我只检索本地主机的 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"];
}
结果,
要求的详细信息:
【问题讨论】:
-
据我所知,您在谈论一些 nginx 类型的反向代理。然后,查看真实客户端 IP 的唯一方法是配置代理服务器以通过 HTTP 标头将其转发到您的应用程序。您知道您使用的代理服务器的名称吗?
-
你好,vorou,是的,我在一周前的某个地方看到了这个 nginx 词。我该如何检查?我实际上有我的最终网站演示,我要做的是在 IIS 上发布网站,然后运行它,然后回到我的问题,在 SAME 网络上获取客户端的内部 IP 地址。我的一位同行告诉我,只需绕过代理服务器就可以得到我想要的东西..
-
如果您的 IIS 与您正在访问它的机器位于同一网络上,您应该能够直接访问它(并在您的应用程序中查看您的实际 IP)。只需确保您通过安装 IIS 的机器的 IP 访问它(如果您不确定是否可以终端进入并运行
ipconfig;查找以IPv4 Address开头的行)。另外,能否展示一下用于获取客户端 IP 的代码? -
让我添加一些屏幕截图和代码示例以及可能需要的信息@vorou 谢谢..
-
我已经编辑了我的问题@vorou
标签: c# asp.net iis proxy ip-address