fix: 离线模式添加对NATType的联控

This commit is contained in:
spiritlhl
2025-06-29 02:34:42 +00:00
parent e540cc384b
commit 3a77ffcdea
3 changed files with 20 additions and 9 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/libp2p/go-nat" "github.com/libp2p/go-nat"
"github.com/oneclickvirt/basics/model" "github.com/oneclickvirt/basics/model"
"github.com/oneclickvirt/basics/system/utils" "github.com/oneclickvirt/basics/system/utils"
precheckUtils "github.com/oneclickvirt/basics/utils"
"github.com/shirou/gopsutil/v4/host" "github.com/shirou/gopsutil/v4/host"
) )
@@ -211,13 +212,15 @@ func getHostInfo() (string, string, string, string, string, string, string, stri
} }
} }
// 查询NAT类型 // 查询NAT类型
NatType = getNatType() if precheckUtils.StackType != "" && precheckUtils.StackType != "None" {
if NatType == "Inconclusive" { NatType = getNatType()
ctx := context.Background() if NatType == "Inconclusive" {
gateway, err := nat.DiscoverGateway(ctx) ctx := context.Background()
if err == nil { gateway, err := nat.DiscoverGateway(ctx)
natType := gateway.Type() if err == nil {
NatType = natType natType := gateway.Type()
NatType = natType
}
} }
} }
// 获取当前系统的本地时区 // 获取当前系统的本地时区

View File

@@ -6,6 +6,7 @@ import (
"github.com/oneclickvirt/basics/model" "github.com/oneclickvirt/basics/model"
"github.com/oneclickvirt/basics/system/utils" "github.com/oneclickvirt/basics/system/utils"
precheckUtils "github.com/oneclickvirt/basics/utils"
. "github.com/oneclickvirt/defaultset" . "github.com/oneclickvirt/defaultset"
) )
@@ -113,7 +114,9 @@ func CheckSystemInfo(language string) string {
res += " Current Time Zone : " + ret.TimeZone + "\n" res += " Current Time Zone : " + ret.TimeZone + "\n"
res += " Load : " + ret.Load + "\n" res += " Load : " + ret.Load + "\n"
res += " VM Type : " + ret.VmType + "\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 != "" { if ret.TcpAccelerationMethod != "" {
res += " Tcp Accelerate : " + ret.TcpAccelerationMethod + "\n" res += " Tcp Accelerate : " + ret.TcpAccelerationMethod + "\n"
} }
@@ -165,7 +168,9 @@ func CheckSystemInfo(language string) string {
res += " 时区 : " + ret.TimeZone + "\n" res += " 时区 : " + ret.TimeZone + "\n"
res += " 负载 : " + ret.Load + "\n" res += " 负载 : " + ret.Load + "\n"
res += " 虚拟化架构 : " + ret.VmType + "\n" res += " 虚拟化架构 : " + ret.VmType + "\n"
res += " NAT类型 : " + ret.NatType + "\n" if precheckUtils.StackType != "" && precheckUtils.StackType != "None" {
res += " NAT类型 : " + ret.NatType + "\n"
}
if ret.TcpAccelerationMethod != "" { if ret.TcpAccelerationMethod != "" {
res += " TCP加速方式 : " + ret.TcpAccelerationMethod + "\n" res += " TCP加速方式 : " + ret.TcpAccelerationMethod + "\n"
} }

View File

@@ -8,6 +8,8 @@ import (
"time" "time"
) )
var StackType string // 联控stun检测
type NetCheckResult struct { type NetCheckResult struct {
HasIPv4 bool HasIPv4 bool
HasIPv6 bool HasIPv6 bool
@@ -151,6 +153,7 @@ result:
} else if hasV6 { } else if hasV6 {
stack = "IPv6" stack = "IPv6"
} }
StackType = stack
return NetCheckResult{ return NetCheckResult{
HasIPv4: hasV4, HasIPv4: hasV4,
HasIPv6: hasV6, HasIPv6: hasV6,