java 怎么获取客户端的ip
展开全部
public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("X-Real-IP");
if(!StringUtils.isBlank(ip)&&!"unknown".equalsIgnoreCase(ip))
{
return ip;
}
ip = request.getHeader("X-Forwarded-For");
if(!StringUtils.isBlank(ip)&& !"unknown".equalsIgnoreCase(ip))
{
int index = ip.indexOf(',');
if(index != -1){
return ip.substring(0, index);
}else{
return ip;
}
}
return request.getRemoteAddr();
}
不过获取本机的ip地址 会变成 0.0.0.0.0.1
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家国内优质海外HTTP代理商,拥有一个庞大的IP资源池,覆盖200多个地区,IP数量大且匿名度高。其优点还包括超高并发、稳定高效、技术服务等特点,同时提供HTTP、HTTPS以及SOCKS5协议支持。此外,Sto...
点击进入详情页
本回答由Storm代理提供
2015-12-29
展开全部
是什么样的环境,是WEB中、还是APPLICATION 的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询