码迷,mamicode.com
首页 > 编程语言 > 详细

Java获取客户端真实IP地址

时间:2016-02-05 11:46:34      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
 1 public String getIpAddr(HttpServletRequest request) { 
 2        String ip = request.getHeader("x-forwarded-for"); 
 3        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
 4            ip = request.getHeader("Proxy-Client-IP"); 
 5        } 
 6        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
 7            ip = request.getHeader("WL-Proxy-Client-IP"); 
 8        } 
 9        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
10            ip = request.getRemoteAddr(); 
11        } 
12        return ip; 
13    }
View Code

 

Java获取客户端真实IP地址

标签:

原文地址:http://www.cnblogs.com/-lpf/p/5182813.html

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