如何在java中获取用户的ip地址 [英] how to get users ip address in java

查看:90
本文介绍了如何在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.

这篇关于如何在java中获取用户的ip地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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