How to get the client IP?

Spread the love

Question Description

While this sounds silly, I haven’t been able to find a way to get the IP of the client in Play 2.0. It was available in 1.2.x as Http.Request.remoteAddress, but 2.0 (I primarily checked the Scala API, but I did a quick check of the Java one too) only seems to provide information about the server side of the request in play(.api).mvc.Request. Is there something I’m missing? The closest hack I can think of right now is setting it up behind a reverse proxy and then checking X-Forwarded-For, but this doesn’t work too well in dev.

Practice As Follows

EDIT:Coming back to this answer, this was added in playframework 2.0.2: see release announcement on!msg/play-framework/Z97GQ2VnR5M/T-STGaeuN68J%5B1-25%5D and more importantly the API documentation at

As you can see there is now support for Request.remoteAddress


There is currently a bug open for this in the tracker:

I think that hacking the play2.0 libraries to include the linked patch is currently the best bet. It is probably still cleaner than to use a proxy with the sole purpose of adding XFF headers, and using those to determine the IP.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.