diff --git a/goecs.go b/goecs.go index 3252e88..7aa4de1 100644 --- a/goecs.go +++ b/goecs.go @@ -59,7 +59,7 @@ var ( autoChangeDiskTestMethod = true filePath = "goecs.txt" enabelUpload = true - help bool + onlyIpInfoCheckStatus, help bool goecsFlag = flag.NewFlagSet("goecs", flag.ContinueOnError) finish bool IPV4, IPV6 string @@ -181,6 +181,7 @@ func initLogger() { } } +// TODO: 6 7 9 10 以及 纯命令行模式 需要加入一个函数查询和输出ASN和地址,方便后续一些网络查询的依赖函数调用 func handleMenuMode(preCheck utils.NetCheckResult) { basicStatus, cpuTestStatus, memoryTestStatus, diskTestStatus = false, false, false, false commTestStatus, utTestStatus, securityTestStatus, emailTestStatus = false, false, false, false @@ -377,6 +378,7 @@ func setUnlockFocusedTestStatus(preCheck utils.NetCheckResult) { } func setNetworkOnlyTestStatus() { + onlyIpInfoCheckStatus = true securityTestStatus = true speedTestStatus = true backtraceStatus = true @@ -385,9 +387,9 @@ func setNetworkOnlyTestStatus() { } func setUnlockOnlyTestStatus() { + onlyIpInfoCheckStatus = true commTestStatus = true utTestStatus = true - enabelUpload = false } func setHardwareOnlyTestStatus(preCheck utils.NetCheckResult) { @@ -401,15 +403,16 @@ func setHardwareOnlyTestStatus(preCheck utils.NetCheckResult) { } func setIPQualityTestStatus() { + onlyIpInfoCheckStatus = true securityTestStatus = true emailTestStatus = true } func setRouteTestStatus() { + onlyIpInfoCheckStatus = true backtraceStatus = true nt3Status = true pingTestStatus = true - enabelUpload = false } func printInvalidChoice() { @@ -511,6 +514,9 @@ func runChineseTests(preCheck utils.NetCheckResult, wg1, wg2, wg3 *sync.WaitGrou *output = runCPUTest(*output, tempOutput, outputMutex) *output = runMemoryTest(*output, tempOutput, outputMutex) *output = runDiskTest(*output, tempOutput, outputMutex) + if onlyIpInfoCheckStatus && !basicStatus && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { + *output = runIpInfoCheck(*output, tempOutput, outputMutex) + } if (onlyChinaTest || pingTestStatus) && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { wg3.Add(1) go func() { @@ -551,6 +557,9 @@ func runEnglishTests(preCheck utils.NetCheckResult, wg1, wg2 *sync.WaitGroup, ba *output = runCPUTest(*output, tempOutput, outputMutex) *output = runMemoryTest(*output, tempOutput, outputMutex) *output = runDiskTest(*output, tempOutput, outputMutex) + if onlyIpInfoCheckStatus && !basicStatus && preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { + *output = runIpInfoCheck(*output, tempOutput, outputMutex) + } if preCheck.Connected && preCheck.StackType != "" && preCheck.StackType != "None" { if utTestStatus { wg1.Add(1) @@ -574,6 +583,22 @@ func runEnglishTests(preCheck utils.NetCheckResult, wg1, wg2 *sync.WaitGroup, ba *output = appendTimeInfo(*output, tempOutput, startTime, outputMutex) } +func runIpInfoCheck(output, tempOutput string, outputMutex *sync.Mutex) string { + outputMutex.Lock() + defer outputMutex.Unlock() + return utils.PrintAndCapture(func() { + _, _, ipinfo := utils.OnlyBasicsIpInfo(language) + if ipinfo != "" { + if language == "zh" { + utils.PrintCenteredTitle("IP信息", width) + } else { + utils.PrintCenteredTitle("IP-Information", width) + } + fmt.Printf("%s", ipinfo) + } + }, tempOutput, output) +} + func runBasicTests(preCheck utils.NetCheckResult, basicInfo, securityInfo *string, output, tempOutput string, outputMutex *sync.Mutex) string { outputMutex.Lock() defer outputMutex.Unlock() diff --git a/utils/utils.go b/utils/utils.go index 922d301..642548a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -19,6 +19,7 @@ import ( "github.com/imroc/req/v3" "github.com/oneclickvirt/UnlockTests/uts" + bnetwork "github.com/oneclickvirt/basics/network" "github.com/oneclickvirt/basics/system" butils "github.com/oneclickvirt/basics/utils" . "github.com/oneclickvirt/defaultset" @@ -115,18 +116,38 @@ func CheckChina(enableLogger bool) bool { return selectChina } +// OnlyBasicsIpInfo 仅检查和输出IP信息 +func OnlyBasicsIpInfo(language string) (string, string, string) { + ipv4, ipv6, ipInfo, _, err := bnetwork.NetworkCheck("both", false, language) + if err != nil { + return "", "", "" + } + basicInfo := ipInfo + if strings.Contains(ipInfo, "IPV4") && strings.Contains(ipInfo, "IPV6") && ipv4 != "" && ipv6 != "" { + uts.IPV4 = true + uts.IPV6 = true + } else if strings.Contains(ipInfo, "IPV4") && ipv4 != "" { + uts.IPV4 = true + uts.IPV6 = false + } else if strings.Contains(ipInfo, "IPV6") && ipv6 != "" { + uts.IPV6 = true + uts.IPV4 = false + } + basicInfo = strings.ReplaceAll(basicInfo, "\n\n", "\n") + return ipv4, ipv6, basicInfo +} + // BasicsAndSecurityCheck 执行安全检查 func BasicsAndSecurityCheck(language, nt3CheckType string, securityCheckStatus bool) (string, string, string, string, string) { var wgt sync.WaitGroup var ipv4, ipv6, ipInfo, securityInfo, systemInfo string - var err error wgt.Add(1) go func() { defer wgt.Done() - ipv4, ipv6, ipInfo, securityInfo, err = network.NetworkCheck("both", securityCheckStatus, language) - if err != nil { - fmt.Println(err.Error()) - } + ipv4, ipv6, ipInfo, securityInfo, _ = network.NetworkCheck("both", securityCheckStatus, language) + // if err != nil { + // fmt.Println(err.Error()) + // } }() wgt.Add(1) go func() {