From 3a77ffcdeab443c39cbed7694c7f03f456e03466 Mon Sep 17 00:00:00 2001 From: spiritlhl <103393591+spiritLHLS@users.noreply.github.com> Date: Sun, 29 Jun 2025 02:34:42 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A6=BB=E7=BA=BF=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9NATType=E7=9A=84=E8=81=94=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system/host.go | 17 ++++++++++------- system/system.go | 9 +++++++-- utils/utils.go | 3 +++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/system/host.go b/system/host.go index b5bbdaf..2991ea3 100644 --- a/system/host.go +++ b/system/host.go @@ -13,6 +13,7 @@ import ( "github.com/libp2p/go-nat" "github.com/oneclickvirt/basics/model" "github.com/oneclickvirt/basics/system/utils" + precheckUtils "github.com/oneclickvirt/basics/utils" "github.com/shirou/gopsutil/v4/host" ) @@ -211,13 +212,15 @@ func getHostInfo() (string, string, string, string, string, string, string, stri } } // 查询NAT类型 - NatType = getNatType() - if NatType == "Inconclusive" { - ctx := context.Background() - gateway, err := nat.DiscoverGateway(ctx) - if err == nil { - natType := gateway.Type() - NatType = natType + if precheckUtils.StackType != "" && precheckUtils.StackType != "None" { + NatType = getNatType() + if NatType == "Inconclusive" { + ctx := context.Background() + gateway, err := nat.DiscoverGateway(ctx) + if err == nil { + natType := gateway.Type() + NatType = natType + } } } // 获取当前系统的本地时区 diff --git a/system/system.go b/system/system.go index e262be9..cf5e52b 100644 --- a/system/system.go +++ b/system/system.go @@ -6,6 +6,7 @@ import ( "github.com/oneclickvirt/basics/model" "github.com/oneclickvirt/basics/system/utils" + precheckUtils "github.com/oneclickvirt/basics/utils" . "github.com/oneclickvirt/defaultset" ) @@ -113,7 +114,9 @@ func CheckSystemInfo(language string) string { res += " Current Time Zone : " + ret.TimeZone + "\n" res += " Load : " + ret.Load + "\n" res += " VM Type : " + ret.VmType + "\n" - res += " NAT Type : " + ret.NatType + "\n" + if precheckUtils.StackType != "" && precheckUtils.StackType != "None" { + res += " NAT Type : " + ret.NatType + "\n" + } if ret.TcpAccelerationMethod != "" { res += " Tcp Accelerate : " + ret.TcpAccelerationMethod + "\n" } @@ -165,7 +168,9 @@ func CheckSystemInfo(language string) string { res += " 时区 : " + ret.TimeZone + "\n" res += " 负载 : " + ret.Load + "\n" res += " 虚拟化架构 : " + ret.VmType + "\n" - res += " NAT类型 : " + ret.NatType + "\n" + if precheckUtils.StackType != "" && precheckUtils.StackType != "None" { + res += " NAT类型 : " + ret.NatType + "\n" + } if ret.TcpAccelerationMethod != "" { res += " TCP加速方式 : " + ret.TcpAccelerationMethod + "\n" } diff --git a/utils/utils.go b/utils/utils.go index 786f716..cf3b6c4 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -8,6 +8,8 @@ import ( "time" ) +var StackType string // 联控stun检测 + type NetCheckResult struct { HasIPv4 bool HasIPv6 bool @@ -151,6 +153,7 @@ result: } else if hasV6 { stack = "IPv6" } + StackType = stack return NetCheckResult{ HasIPv4: hasV4, HasIPv6: hasV6,