如何获得客户端IP? [英] How to get the client IP?

查看:104
本文介绍了如何获得客户端IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然听起来很愚蠢,但我还没找到在Play 2.0中获取客户端IP的方法.它在1.2.x中以Http.Request.remoteAddress的形式提供,但2.0(我主要检查了Scala API,但我也对Java进行了快速检查)似乎只提供了有关play(.api).mvc.Request中请求服务器端的信息. .有什么我想念的吗?我现在想到的最接近的黑客方法是将其设置在反向代理后面,然后检查X-Forwarded-For,但这在开发人员中效果不佳.

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.

推荐答案

回到此答案,此内容已在playframework 2.0.2中添加:请参见 http://www.playframework.org/documentation/api/2.0.2/scala/index.html#play.api.mvc.Request

Coming back to this answer, this was added in playframework 2.0.2: see release announcement on https://groups.google.com/forum/#!msg/play-framework/Z97GQ2VnR5M/T-STGaeuN68J%5B1-25%5D and more importantly the API documentation at http://www.playframework.org/documentation/api/2.0.2/scala/index.html#play.api.mvc.Request

如您所见,现在支持Request.remoteAddress

原文:

跟踪器当前为此打开一个错误: https://play .lighthouseapp.com/projects/82401/tickets/256-add-back-requestheaderremoteaddress

There is currently a bug open for this in the tracker: https://play.lighthouseapp.com/projects/82401/tickets/256-add-back-requestheaderremoteaddress

我认为,最好的方法是黑客入侵play2.0库以包含链接的补丁程序.与仅使用添加XFF标头并使用它们确定IP的目的使用代理相比,它可能仍然更干净.

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.

这篇关于如何获得客户端IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆