Application Application Request Headers for IP Address

I have an application for applications that runs REST web services. I want to extract the ip address from all requests processed by my web services.

from javax.servlet.http.HttpServletRequest I try to extract the ip address by checking "X-Real-IP" if empty or unknown checks the first ip in the list of "X-Forwarded-For header, if empty or" unknown. get it from request.getRemoteAddr ().

It seemed to me that I covered all cases, but I still get ip addresses such as 10.xxx or 127.0.0.1 or unknown.

I know that applications for application applications work for load balancers, and instances are dynamic, and of course I omit the header in the request because I can see the source IP address in the logs (from Google).

Edit: all the requests I'm working on are a direct service request (no requests in the queue or cron).

Any idea of ​​other headers to check?

thank.

+4
source share
1 answer

Answers to this question may help you. There are many headers to check:

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" };
+1
source

Source: https://habr.com/ru/post/1589433/


All Articles