Merge remote-tracking branch 'origin/master'

master
星期八 5 years ago
commit 3636d63fd4
  1. 11
      src/main/java/com/lq/webUtil/util/IPUtil.java

@ -9,16 +9,21 @@ import java.net.UnknownHostException;
*/ */
public class IPUtil { public class IPUtil {
/**
* 未知ip
*/
public static final String IP_UNKNOWM = "unknown";
public static String getIP(HttpServletRequest request){ public static String getIP(HttpServletRequest request){
String ip = request.getHeader("x-forwarded-for"); String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ if(ip == null || ip.length() == 0 || IP_UNKNOWM.equalsIgnoreCase(ip)){
ip = request.getHeader("Proxy-Client-IP"); ip = request.getHeader("Proxy-Client-IP");
} }
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ if(ip == null || ip.length() == 0 || IP_UNKNOWM.equalsIgnoreCase(ip)){
ip = request.getHeader("WL-Proxy-Client-IP"); ip = request.getHeader("WL-Proxy-Client-IP");
} }
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ if(ip == null || ip.length() == 0 || IP_UNKNOWM.equalsIgnoreCase(ip)){
ip = request.getRemoteAddr(); ip = request.getRemoteAddr();
} }
return "0:0:0:0:0:0:0:1".equals(ip) ?"127.0.0.1":ip; return "0:0:0:0:0:0:0:1".equals(ip) ?"127.0.0.1":ip;

Loading…
Cancel
Save