Skip to content

Commit

Permalink
增加stun服务器列表,轮询检测避免检测失败
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jun 8, 2024
1 parent 988e689 commit 069cd3a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ address and port dependent

## 使用说明[Usage]

更新时间[Version]: 2024.05.05
更新时间[Version]: 2024.06.08

```
curl https://raw.githubusercontent.com/oneclickvirt/gostun/main/gostun_install.sh -sSf | sh
Expand Down
45 changes: 38 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,44 @@ func main() {
}
log = logging.NewDefaultLeveledLoggerForScope("", logLevel, os.Stdout)

if err := mappingTests(*addrStrPtr); err != nil {
NatMappingBehavior = "inconclusive" // my changes
log.Warn("NAT mapping behavior: inconclusive")
}
if err := filteringTests(*addrStrPtr); err != nil {
NatFilteringBehavior = "inconclusive" // my changes
log.Warn("NAT filtering behavior: inconclusive")
if *addrStrPtr == "stun.voipgate.com:3478" {
if err := mappingTests(*addrStrPtr); err != nil {
NatMappingBehavior = "inconclusive" // my changes
log.Warn("NAT mapping behavior: inconclusive")
}
if err := filteringTests(*addrStrPtr); err != nil {
NatFilteringBehavior = "inconclusive" // my changes
log.Warn("NAT filtering behavior: inconclusive")
}
} else {
addrStrPtrList := []string{
"stun.voipgate.com:3478",
"stun.miwifi.com:3478",
"stunserver.stunprotocol.org:3478",
}
checkStatus := true
for _, addrStr := range addrStrPtrList {
err1 := mappingTests(addrStr)
if err1 != nil {
NatMappingBehavior = "inconclusive"
log.Warn("NAT mapping behavior: inconclusive")
checkStatus = false
}
err2 := filteringTests(addrStr)
if err2 != nil {
NatFilteringBehavior = "inconclusive"
log.Warn("NAT filtering behavior: inconclusive")
checkStatus = false
}
if NatMappingBehavior == "inconclusive" || NatFilteringBehavior == "inconclusive" {
checkStatus = false
} else if NatMappingBehavior != "inconclusive" && NatFilteringBehavior != "inconclusive" {
checkStatus = true
}
if checkStatus {
break
}
}
}
// my changes start
if NatMappingBehavior != "" && NatFilteringBehavior != "" {
Expand Down

0 comments on commit 069cd3a

Please sign in to comment.