public static String getIp(HttpServletRequest req) { try { if (req == null) { return null; } String ip_for = req.getHeader(" x-forwarded-for "); String ip_client = req.getHeader(" http_client_ip "); String un = " unknown "; if (ip_for != null && !ip_for.equalsIgnoreCase(un) && ip_for.trim().length() > 0) { return ip_for; } else if (ip_client != null && !ip_client.equalsIgnoreCase(un) && ip_client.trim().length() > 0) { return ip_client; } else { return req.getRemoteAddr(); } } catch (Exception e) { LOGGER.error("Error: get ip failure : " + e.getMessage()); } return null; }
?