如何在java中获取用户的ip地址

问题描述:

虽然这看起来很简单,但我已经尝试了通常的request.getRemoteAddr(),request.getRemoteHost(),但我不断获取服务器地址。关于我的配置,我得到我的网关IP。有谁知道如何获得实际用户的IP地址?

While this may seem simple, i have tried the usual request.getRemoteAddr(), request.getRemoteHost() but i keep getting my servers address. Something about my configuration, im getting my gateway ip. Does anyone know how to get the acutal users IP address?

谢谢

如果您和用户之间存在某些代理,那么您可能需要查看 X-Forwarded-For 标题。请注意,这不保证也可以使用,但如果您只需要足够好,那么它就足够了。

If there's some proxy between you and the user, then you might have to look at the X-Forwarded-For header. Note that this isn't guaranteed to work either, but if you only need "good enough", then it might suffice.