From 409a9526b95d2e045541f818c5dbde5d45c57dd1 Mon Sep 17 00:00:00 2001 From: jianjun Date: Mon, 6 Jul 2020 10:23:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=8E=B7=E5=8F=96ip=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/commons/tools/utils/IpUtils.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IpUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IpUtils.java index 9ed1317906..c2fb803764 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IpUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/IpUtils.java @@ -49,6 +49,12 @@ public class IpUtils { if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } + //对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割 + if (ip != null && ip.length() > 15) { //"***.***.***.***".length() = 15 + if (ip.indexOf(",") > 0) { + ip = ip.substring(0, ip.indexOf(",")); + } + } } catch (Exception e) { logger.error("IpUtils ERROR ", e); } @@ -58,6 +64,7 @@ public class IpUtils { /** * desc:获取本地Ip + * * @return */ public static String getServerIp() {