Skip to content

Commit 3a77ffc

Browse files
committed
fix: 离线模式添加对NATType的联控
1 parent e540cc3 commit 3a77ffc

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

system/host.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/libp2p/go-nat"
1414
"github.com/oneclickvirt/basics/model"
1515
"github.com/oneclickvirt/basics/system/utils"
16+
precheckUtils "github.com/oneclickvirt/basics/utils"
1617
"github.com/shirou/gopsutil/v4/host"
1718
)
1819

@@ -211,13 +212,15 @@ func getHostInfo() (string, string, string, string, string, string, string, stri
211212
}
212213
}
213214
// 查询NAT类型
214-
NatType = getNatType()
215-
if NatType == "Inconclusive" {
216-
ctx := context.Background()
217-
gateway, err := nat.DiscoverGateway(ctx)
218-
if err == nil {
219-
natType := gateway.Type()
220-
NatType = natType
215+
if precheckUtils.StackType != "" && precheckUtils.StackType != "None" {
216+
NatType = getNatType()
217+
if NatType == "Inconclusive" {
218+
ctx := context.Background()
219+
gateway, err := nat.DiscoverGateway(ctx)
220+
if err == nil {
221+
natType := gateway.Type()
222+
NatType = natType
223+
}
221224
}
222225
}
223226
// 获取当前系统的本地时区

system/system.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/oneclickvirt/basics/model"
88
"github.com/oneclickvirt/basics/system/utils"
9+
precheckUtils "github.com/oneclickvirt/basics/utils"
910
. "github.com/oneclickvirt/defaultset"
1011
)
1112

@@ -113,7 +114,9 @@ func CheckSystemInfo(language string) string {
113114
res += " Current Time Zone : " + ret.TimeZone + "\n"
114115
res += " Load : " + ret.Load + "\n"
115116
res += " VM Type : " + ret.VmType + "\n"
116-
res += " NAT Type : " + ret.NatType + "\n"
117+
if precheckUtils.StackType != "" && precheckUtils.StackType != "None" {
118+
res += " NAT Type : " + ret.NatType + "\n"
119+
}
117120
if ret.TcpAccelerationMethod != "" {
118121
res += " Tcp Accelerate : " + ret.TcpAccelerationMethod + "\n"
119122
}
@@ -165,7 +168,9 @@ func CheckSystemInfo(language string) string {
165168
res += " 时区 : " + ret.TimeZone + "\n"
166169
res += " 负载 : " + ret.Load + "\n"
167170
res += " 虚拟化架构 : " + ret.VmType + "\n"
168-
res += " NAT类型 : " + ret.NatType + "\n"
171+
if precheckUtils.StackType != "" && precheckUtils.StackType != "None" {
172+
res += " NAT类型 : " + ret.NatType + "\n"
173+
}
169174
if ret.TcpAccelerationMethod != "" {
170175
res += " TCP加速方式 : " + ret.TcpAccelerationMethod + "\n"
171176
}

utils/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"time"
99
)
1010

11+
var StackType string // 联控stun检测
12+
1113
type NetCheckResult struct {
1214
HasIPv4 bool
1315
HasIPv6 bool
@@ -151,6 +153,7 @@ result:
151153
} else if hasV6 {
152154
stack = "IPv6"
153155
}
156+
StackType = stack
154157
return NetCheckResult{
155158
HasIPv4: hasV4,
156159
HasIPv6: hasV6,

0 commit comments

Comments
 (0)