|
@@ -27,13 +27,28 @@ public class IpUtils {
|
|
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
ip = request.getHeader("X-Real-IP");
|
|
|
}
|
|
|
-
|
|
|
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
|
|
ip = request.getRemoteAddr();
|
|
|
}
|
|
|
- return "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : EscapeUtil.clean(ip);
|
|
|
+ if ("0:0:0:0:0:0:0:1".equals(ip)) {
|
|
|
+ ip = "127.0.0.1";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取第一个非 "unknown" 的 IP 地址,防止用户端使用多重代理时IP为多个
|
|
|
+ if (ip != null && ip.contains(",")) {
|
|
|
+ String[] ips = ip.split(",");
|
|
|
+ for (String singleIp : ips) {
|
|
|
+ if (!"unknown".equalsIgnoreCase(singleIp.trim())) {
|
|
|
+ ip = singleIp.trim();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return EscapeUtil.clean(ip);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public static boolean internalIp(String ip) {
|
|
|
byte[] addr = textToNumericFormatV4(ip);
|
|
|
return internalIp(addr) || "127.0.0.1".equals(ip);
|