如何从 headers 获取 OriginatingClientIPAddress?

How to get OriginatingClientIPAddress from headers?

如何在不询问权限的情况下自动从 header 读取 X-Forwarded-For?

我现在面临的问题是,用户通过第三方服务器访问我的网站,结果当我请求 ip 时,我得到的是代理服务器的 ip,而不是原始 ip client的ip.I可以从x-forwarded-for字段获取,但是没有x-forwarded-for字段怎么获取呢?

您所要求的是一种行之有效的执行拒绝服务攻击的方法。

Changing the IP of the request from your third party server won't help you because then you won't be able to get a response from your website as your website would then send the response to the ip from where the request originated (to the website).

也就是说,您必须使用x-forwarded-for字段,事实上这是唯一的原因为了这个 header 存在。


解决方案

When the third party server receives a request (original) you need to set the x-forwarded-for header of the new request (generated) to that of the IP of the (original) request. So when you send the (generated) request to your website, use the x-forwarded-for header to collect the IP of the (original) request.

希望说得通:)