Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App engine request headers for ip address

I have an app engine application that runs REST web services. I want to extract the ip address from all requests that are handled by my web services.

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().

I thought i covered all the cases but i'm still getting ip addresses like 10.x.x.x, or 127.0.0.1 or unknown.

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) .

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

Any idea of the other headers to check ?

thx .

like image 838
Akli REGUIG Avatar asked Oct 31 '22 03:10

Akli REGUIG


1 Answers

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" };
like image 119
Lukas Avatar answered Nov 11 '22 15:11

Lukas