获取用户的IP地址,作为防钓鱼的一种方法

获取用户的IP地址,作为防钓鱼的一种方法

String clientIp = request.getHeader("x-forwarded-for");
        if ((clientIp == null) || (clientIp.length() == 0)
                || ("unknown".equalsIgnoreCase(clientIp))) {
            clientIp = request.getHeader("Proxy-Client-IP");
        }
        if ((clientIp == null) || (clientIp.length() == 0)
                || ("unknown".equalsIgnoreCase(clientIp))) {
            clientIp = request.getHeader("WL-Proxy-Client-IP");
        }
        if ((clientIp == null) || (clientIp.length() == 0)
                || ("unknown".equalsIgnoreCase(clientIp))) {
            clientIp = request.getRemoteAddr();
        }
        String ipAddress = clientIp;

你可能感兴趣的:(JavaWeb)