如何从java中的请求获取客户端的浏览器ip?

时间:2013-02-26 05:58:57

标签: java java-ee

我知道从java中的httprequest获取客户端的IP和服务器IP非常容易。是否有可能以任何方式获取客户端的浏览器IP。

提前致谢

1 个答案:

答案 0 :(得分:5)

据我所知,

您可以通过方法获取客户端IP

HttpServletRequest httpRequest = (HttpServletRequest) request;
String userIpAddress = httpRequest.getHeader("X-Forwarded-For");

完整报价: How to determine by what IP Address my website has been accessed?

从请求获取服务器IP

HttpServletRequest.getLocalAddr();

完整报价:Getting server address and application name

获取服务器ips可以这样做

Inet4Address.getLocalHost().getHostAddress()

完整报价: Getting the IP address of the current machine using Java

相关问题