public String getIp(HttpServletRequest req) {
// X-Forwarded-For位于HTTP协议的请求头
String ip = req.getHeader("X-Forwarded-For");
if (null == ip) {
ip = request.getRemoteAddr();
}
if (ip.indexOf(',') > -1) {
ip = ip.substring(0, ip.indexOf(',')).trim();
}
return ip;
}
通过 Java 获取发起访问的客户端的IP地址
最新推荐文章于 2023-01-09 17:01:27 发布