From 1067320b3ea7f8f1e5a7f7f9621f85fd3a7841b0 Mon Sep 17 00:00:00 2001 From: qi Date: Sun, 12 Apr 2020 07:06:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E9=99=A4=E9=AD=94=E6=B3=95=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/lq/webUtil/util/IPUtil.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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;