首页 > 编程语言 > 详细

java获取客户端ip

时间:2018-03-30 15:35:56      阅读:150      评论:0      收藏:0      [点我收藏+]
public String getIpAddr(HttpServletRequest request) { 
     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(); 
     } 
    return ip; 
   } 

 

java获取客户端ip

原文:https://www.cnblogs.com/lansetuerqi/p/8508309.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!