简体   繁体   English

用于IP地址的应用引擎请求标头

[英]App engine request headers for ip address

I have an app engine application that runs REST web services. 我有一个运行REST Web服务的应用程序引擎应用程序。 I want to extract the ip address from all requests that are handled by my web services. 我想从我的Web服务处理的所有请求中提取IP地址。

from javax.servlet.http.HttpServletRequest i'm trying to extract the ip address checking the "X-Real-IP" , if empty or "unknown" check the first ip in the list of "X-Forwarded-For" header if empty or "unknown" get it from request.getRemoteAddr(). 来自javax.servlet.http.HttpServletRequest我正在尝试提取检查“X-Real-IP”的IP地址,如果为空或“未知”,请检查“X-Forwarded-For”标题列表中的第一个ip,如果空或“未知”从request.getRemoteAddr()获取它。

I thought i covered all the cases but i'm still getting ip addresses like 10.xxx, or 127.0.0.1 or unknown. 我以为我覆盖了所有的情况,但我仍然得到像10.xxx,或127.0.0.1或未知的IP地址。

I know that app engine applications are running behind load balancers, and instances are dynamic and i'm certainly omitting a header in the request cuz i can see the original ip address in the logs (from google) . 我知道应用程序引擎应用程序正在负载均衡器后面运行,实例是动态的,我当然在请求中省略了一个标题,因为我可以在日志中看到原始的IP地址(来自谷歌)。

Edit : all the requests i'm working on are direct request to service (no queue or cron requests). 编辑:我正在处理的所有请求都是直接请求服务(没有队列或cron请求)。

Any idea of the other headers to check ? 想知道其他标题要检查吗?

thx . 谢谢 。

The answeres of this Question might help you. 回答这个问题可能会对你有所帮助。 There are a lot of headers to check for: 要检查的标题很多:

private static final String[] HEADERS_TO_TRY = { 
    "X-Forwarded-For",
    "Proxy-Client-IP",
    "WL-Proxy-Client-IP",
    "HTTP_X_FORWARDED_FOR",
    "HTTP_X_FORWARDED",
    "HTTP_X_CLUSTER_CLIENT_IP",
    "HTTP_CLIENT_IP",
    "HTTP_FORWARDED_FOR",
    "HTTP_FORWARDED",
    "HTTP_VIA",
    "REMOTE_ADDR" };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM