mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-08 16:57:09 +08:00
fix(log/core): 兼容日志记录 IPv6 IP 归属地场景
This commit is contained in:
@@ -44,8 +44,8 @@ public class IpUtils {
|
||||
* @param ip IP 地址
|
||||
* @return IP 归属地
|
||||
*/
|
||||
public static String getAddress(String ip) {
|
||||
if (isInnerIp(ip)) {
|
||||
public static String getIpv4Address(String ip) {
|
||||
if (isInnerIpv4(ip)) {
|
||||
return "内网IP";
|
||||
}
|
||||
Ip2regionSearcher ip2regionSearcher = SpringUtil.getBean(Ip2regionSearcher.class);
|
||||
@@ -64,7 +64,7 @@ public class IpUtils {
|
||||
* @param ip IP 地址
|
||||
* @return 是否为内网 IP
|
||||
*/
|
||||
public static boolean isInnerIp(String ip) {
|
||||
public static boolean isInnerIpv4(String ip) {
|
||||
return NetUtil.isInnerIP("0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip));
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ package top.continew.starter.log.core.model;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import top.continew.starter.core.util.ExceptionUtils;
|
||||
import top.continew.starter.core.util.IpUtils;
|
||||
import top.continew.starter.log.core.enums.Include;
|
||||
import top.continew.starter.web.util.ServletUtils;
|
||||
@@ -89,7 +90,9 @@ public class LogRequest {
|
||||
} else if (includes.contains(Include.REQUEST_PARAM)) {
|
||||
this.param = request.getParam();
|
||||
}
|
||||
this.address = (includes.contains(Include.IP_ADDRESS)) ? IpUtils.getAddress(this.ip) : null;
|
||||
this.address = (includes.contains(Include.IP_ADDRESS))
|
||||
? ExceptionUtils.exToNull(() -> IpUtils.getIpv4Address(this.ip))
|
||||
: null;
|
||||
if (null == this.headers) {
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user