mirror of
https://github.com/oneclickvirt/basics.git
synced 2026-04-23 00:37:11 +08:00
fix: 增强gostun的检测能力,更新版本
This commit is contained in:
@@ -7,9 +7,8 @@ require (
|
||||
github.com/jaypipes/ghw v0.12.0
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/libp2p/go-nat v0.2.0
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/oneclickvirt/defaultset v0.0.2-20240624082446
|
||||
github.com/oneclickvirt/gostun v0.0.3-20250329105202
|
||||
github.com/oneclickvirt/gostun v0.0.5-20250722144757
|
||||
github.com/shirou/gopsutil/v4 v4.24.5
|
||||
github.com/yusufpapurcu/wmi v1.2.4
|
||||
golang.org/x/sys v0.21.0
|
||||
|
||||
@@ -62,12 +62,10 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
|
||||
github.com/oneclickvirt/defaultset v0.0.2-20240624082446/go.mod h1:e9Jt4tf2sbemCtc84/XgKcHy9EZ2jkc5x2sW1NiJS+E=
|
||||
github.com/oneclickvirt/gostun v0.0.3-20250329105202 h1:aJ6E91Lp94lq8iWRcCaxpXTjqOOaWvufr5oras6cFtM=
|
||||
github.com/oneclickvirt/gostun v0.0.3-20250329105202/go.mod h1:f7DPEXAxbmwXSW33dbxtb0/KzqvOBWhTs2Or5xBerQA=
|
||||
github.com/oneclickvirt/gostun v0.0.5-20250722144757 h1:RCEouk5WIJoF52JfsC60Zkqz66JY0JQKrhfd9kqP1OI=
|
||||
github.com/oneclickvirt/gostun v0.0.5-20250722144757/go.mod h1:f7DPEXAxbmwXSW33dbxtb0/KzqvOBWhTs2Or5xBerQA=
|
||||
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
|
||||
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
|
||||
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
|
||||
|
||||
+41
-29
@@ -7,37 +7,49 @@ import (
|
||||
|
||||
func getNatType() string {
|
||||
model.EnableLoger = false
|
||||
addrStrPtrList := []string{
|
||||
"stun.voipgate.com:3478",
|
||||
"stun.miwifi.com:3478",
|
||||
"stunserver.stunprotocol.org:3478",
|
||||
}
|
||||
checkStatus := true
|
||||
for _, addrStr := range addrStrPtrList {
|
||||
err1 := stuncheck.MappingTests(addrStr)
|
||||
if err1 != nil {
|
||||
model.NatMappingBehavior = "inconclusive"
|
||||
if model.EnableLoger {
|
||||
model.Log.Warn("NAT mapping behavior: inconclusive")
|
||||
}
|
||||
checkStatus = false
|
||||
}
|
||||
err2 := stuncheck.FilteringTests(addrStr)
|
||||
if err2 != nil {
|
||||
model.NatFilteringBehavior = "inconclusive"
|
||||
if model.EnableLoger {
|
||||
model.Log.Warn("NAT filtering behavior: inconclusive")
|
||||
}
|
||||
checkStatus = false
|
||||
}
|
||||
if model.NatMappingBehavior == "inconclusive" || model.NatFilteringBehavior == "inconclusive" {
|
||||
checkStatus = false
|
||||
} else if model.NatMappingBehavior != "inconclusive" && model.NatFilteringBehavior != "inconclusive" {
|
||||
checkStatus = true
|
||||
}
|
||||
if checkStatus {
|
||||
model.Verbose = 0
|
||||
model.Timeout = 3
|
||||
model.IPVersion = "ipv4"
|
||||
addrStrList := model.GetDefaultServers(model.IPVersion)
|
||||
rfcMethods := []string{"RFC5780", "RFC5389", "RFC3489"}
|
||||
successfulDetection := false
|
||||
for _, rfcMethod := range rfcMethods {
|
||||
if successfulDetection {
|
||||
break
|
||||
}
|
||||
for _, addrStr := range addrStrList {
|
||||
model.NatMappingBehavior = ""
|
||||
model.NatFilteringBehavior = ""
|
||||
var err1, err2 error
|
||||
switch rfcMethod {
|
||||
case "RFC5780":
|
||||
err1 = stuncheck.MappingTests(addrStr)
|
||||
if err1 != nil {
|
||||
model.NatMappingBehavior = "inconclusive"
|
||||
}
|
||||
err2 = stuncheck.FilteringTests(addrStr)
|
||||
if err2 != nil {
|
||||
model.NatFilteringBehavior = "inconclusive"
|
||||
}
|
||||
case "RFC5389":
|
||||
err1 = stuncheck.MappingTestsRFC5389(addrStr)
|
||||
if err1 != nil {
|
||||
model.NatMappingBehavior = "inconclusive"
|
||||
model.NatFilteringBehavior = "inconclusive"
|
||||
}
|
||||
case "RFC3489":
|
||||
err1 = stuncheck.MappingTestsRFC3489(addrStr)
|
||||
if err1 != nil {
|
||||
model.NatMappingBehavior = "inconclusive"
|
||||
model.NatFilteringBehavior = "inconclusive"
|
||||
}
|
||||
}
|
||||
if model.NatMappingBehavior != "inconclusive" && model.NatFilteringBehavior != "inconclusive" &&
|
||||
model.NatMappingBehavior != "" && model.NatFilteringBehavior != "" {
|
||||
successfulDetection = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return stuncheck.CheckType()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user