IP地址的获取

//ip地址的获取:非原创,之前在其他地方看到,拿过来备份下:

public static String getIPAddress(HttpServletRequest request) { String ip = null; String ipAddresses = request.getHeader("X-Forwarded-For"); if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ipAddresses = request.getHeader("Proxy-Client-IP"); } if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ipAddresses = request.getHeader("WL-Proxy-Client-IP"); } if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ipAddresses = request.getHeader("HTTP_CLIENT_IP"); } if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ipAddresses = request.getHeader("X-Real-IP"); } if(ipAddresses != null && ipAddresses.length() != 0) { ip = ipAddresses.split(",")[0]; } if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) { ip = request.getRemoteAddr(); } return ip; }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzdwfj.html