码迷,mamicode.com
首页 > 其他好文 > 详细

获取访问Ip常用方法

时间:2015-04-14 14:47:16      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:获取ip常用方法

public static String getIpAddr(HttpServletRequest request) {

final String xRealip = request.getHeader("X-Real-IP");

if (StringUtils.isNotEmpty(xRealip)) {

return xRealip;

}

final String cdnIp = request.getHeader("Cdn-Src-Ip");

if (StringUtils.isNotEmpty(cdnIp)) {

return cdnIp;

}

final String forwardIp = request.getHeader("HTTP_X_FORWARDED_FOR");

if (StringUtils.isNotEmpty(forwardIp)) {

return forwardIp;

}

final String realIp = request.getHeader("HTTP_X_REAL_IP");

if (StringUtils.isNotEmpty(realIp)) {

return realIp;

}

final String wlProxyClientIp =  request.getHeader("WL-Proxy-Client-IP");

if (StringUtils.isNotEmpty(wlProxyClientIp)) {

return wlProxyClientIp;

}

final String proxyClientIp =  request.getHeader("Proxy-Client-IP");

if (StringUtils.isNotEmpty(proxyClientIp)) {

return proxyClientIp;

}


return request.getRemoteAddr();

}


本文出自 “逆天” 博客,请务必保留此出处http://xxzjzsj.blog.51cto.com/3052058/1632220

获取访问Ip常用方法

标签:获取ip常用方法

原文地址:http://xxzjzsj.blog.51cto.com/3052058/1632220

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!