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

Java服务器获取客户端的ip

时间:2017-08-03 13:46:49      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:==   remote   ipad   client   servlet   ram   ase   ret   https   

原文:http://www.open-open.com/code/view/1454133120089

 

    /**
     * 获取登录用户IP地址
     * 
     * @param request
     * @return
     */
    public static 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();
        }
        if (ip.equals("0:0:0:0:0:0:0:1")) {
            ip = "本地";
        }
        return ip;
    }

 

Java服务器获取客户端的ip

标签:==   remote   ipad   client   servlet   ram   ase   ret   https   

原文地址:http://www.cnblogs.com/shihaiming/p/7279059.html

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