diff --git a/src/main/java/com/lq/webUtil/util/IPUtil.java b/src/main/java/com/lq/webUtil/util/IPUtil.java index d96b86a..0fe6b02 100755 --- a/src/main/java/com/lq/webUtil/util/IPUtil.java +++ b/src/main/java/com/lq/webUtil/util/IPUtil.java @@ -9,16 +9,21 @@ import java.net.UnknownHostException; */ public class IPUtil { + /** + * 未知ip + */ + public static final String IP_UNKNOWM = "unknown"; + public static String getIP(HttpServletRequest request){ 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"); } - 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"); } - if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)){ + if(ip == null || ip.length() == 0 || IP_UNKNOWM.equalsIgnoreCase(ip)){ ip = request.getRemoteAddr(); } return "0:0:0:0:0:0:0:1".equals(ip) ?"127.0.0.1":ip;