当前位置:   article > 正文

获取访问者IP地址,防代理_获取访问者ip防劫持

获取访问者ip防劫持
  1. public String getClientIP() {
  2. HttpServletRequest request = ServletActionContext.getRequest();
  3. String ip = request.getHeader("x-forwarded-for");
  4. if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
  5. ip = request.getHeader("Proxy-Client-IP");
  6. }
  7. if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
  8. ip = request.getHeader("WL-Proxy-Client-IP");
  9. }
  10. if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
  11. ip = request.getHeader("X-Real-IP");
  12. }
  13. if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
  14. ip = request.getRemoteAddr();
  15. }
  16. return ip;
  17. }

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/758282
推荐阅读
相关标签
  

闽ICP备14008679号