This commit is contained in:
spiritysdx
2024-06-30 20:15:55 +08:00
parent ab91735695
commit 6f0b1556bb
2 changed files with 105 additions and 36 deletions

View File

@@ -131,48 +131,77 @@ func main() {
utils.PrintCenteredTitle("", width) utils.PrintCenteredTitle("", width)
}, tempOutput, output) }, tempOutput, output)
} else if language == "en" { } else if language == "en" {
output = utils.PrintAndCapture(func() {
utils.PrintHead(language, width, ecsVersion) utils.PrintHead(language, width, ecsVersion)
utils.PrintCenteredTitle("Basic Information", width) utils.PrintCenteredTitle("Basic Information", width)
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
basicInfo, securityInfo, nt3CheckType = utils.SecurityCheck(language, nt3CheckType) basicInfo, securityInfo, nt3CheckType = utils.SecurityCheck(language, nt3CheckType)
fmt.Printf(basicInfo) fmt.Printf(basicInfo)
utils.PrintCenteredTitle(fmt.Sprintf("CPU Test - %s Method", cpuTestMethod), width) utils.PrintCenteredTitle(fmt.Sprintf("CPU Test - %s Method", cpuTestMethod), width)
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
cputest.CpuTest(language, cpuTestMethod, cpuTestThreadMode) cputest.CpuTest(language, cpuTestMethod, cpuTestThreadMode)
utils.PrintCenteredTitle(fmt.Sprintf("Memory Test - %s Method", memoryTestMethod), width) utils.PrintCenteredTitle(fmt.Sprintf("Memory Test - %s Method", memoryTestMethod), width)
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
memorytest.MemoryTest(language, memoryTestMethod) memorytest.MemoryTest(language, memoryTestMethod)
utils.PrintCenteredTitle(fmt.Sprintf("Disk Test - %s Method", diskTestMethod), width) utils.PrintCenteredTitle(fmt.Sprintf("Disk Test - %s Method", diskTestMethod), width)
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
memorytest.MemoryTest(language, memoryTestMethod)
utils.PrintCenteredTitle(fmt.Sprintf("Disk Test - %s Method", diskTestMethod), width)
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
disktest.DiskTest(language, diskTestMethod, diskTestPath, diskMultiCheck) disktest.DiskTest(language, diskTestMethod, diskTestPath, diskMultiCheck)
}, tempOutput, output)
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
emailInfo = email.EmailCheck() emailInfo = email.EmailCheck()
}() }()
output = utils.PrintAndCapture(func() {
utils.PrintCenteredTitle("The Three Families Streaming Media Unlock", width) utils.PrintCenteredTitle("The Three Families Streaming Media Unlock", width)
commediatest.ComMediaTest(language) commediatest.ComMediaTest(language)
utils.PrintCenteredTitle("Cross-Border Streaming Media Unlock", width) utils.PrintCenteredTitle("Cross-Border Streaming Media Unlock", width)
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
unlocktest.MediaTest(language) unlocktest.MediaTest(language)
utils.PrintCenteredTitle("IP Quality Check", width) utils.PrintCenteredTitle("IP Quality Check", width)
fmt.Printf(securityInfo) fmt.Printf(securityInfo)
utils.PrintCenteredTitle("Email Port Check", width) utils.PrintCenteredTitle("Email Port Check", width)
}, tempOutput, output)
wg.Wait() wg.Wait()
output = utils.PrintAndCapture(func() {
fmt.Println(emailInfo) fmt.Println(emailInfo)
//utils.PrintCenteredTitle("Return Path Routing", width) //utils.PrintCenteredTitle("Return Path Routing", width)
utils.PrintCenteredTitle("Nearby Node Speed Test", width) utils.PrintCenteredTitle("Nearby Node Speed Test", width)
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
speedtest.ShowHead(language) speedtest.ShowHead(language)
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
speedtest.NearbySP() speedtest.NearbySP()
}, tempOutput, output)
output = utils.PrintAndCapture(func() {
speedtest.CustomSP("net", "global", -1) speedtest.CustomSP("net", "global", -1)
utils.PrintCenteredTitle("", width) utils.PrintCenteredTitle("", width)
}, tempOutput, output)
endTime := time.Now() endTime := time.Now()
duration := endTime.Sub(startTime) duration := endTime.Sub(startTime)
minutes := int(duration.Minutes()) minutes := int(duration.Minutes())
seconds := int(duration.Seconds()) % 60 seconds := int(duration.Seconds()) % 60
fmt.Printf("Cost Time : %d 分 %d 秒\n", minutes, seconds)
currentTime := time.Now().Format("Mon Jan 2 15:04:05 MST 2006") currentTime := time.Now().Format("Mon Jan 2 15:04:05 MST 2006")
output = utils.PrintAndCapture(func() {
fmt.Printf("Cost Time : %d 分 %d 秒\n", minutes, seconds)
fmt.Printf("Current Time : %s\n", currentTime) fmt.Printf("Current Time : %s\n", currentTime)
utils.PrintCenteredTitle("", width) utils.PrintCenteredTitle("", width)
}, tempOutput, output)
} }
shorturl, err := utils.UploadText(output) shorturl, err := utils.UploadText(output)
if err != nil { if err != nil {
fmt.Println("Upload failed, can not generate short URL.") fmt.Println("Upload failed, can not generate short URL.")
fmt.Println(err.Error())
} }
fmt.Println("Upload successful, short URL:", shorturl) fmt.Println("Upload successful, short URL:", shorturl)
} }

View File

@@ -7,6 +7,7 @@ import (
"github.com/oneclickvirt/UnlockTests/uts" "github.com/oneclickvirt/UnlockTests/uts"
"github.com/oneclickvirt/basics/system" "github.com/oneclickvirt/basics/system"
"github.com/oneclickvirt/security/network" "github.com/oneclickvirt/security/network"
"io"
"os" "os"
"strings" "strings"
"sync" "sync"
@@ -87,17 +88,56 @@ func SecurityCheck(language, nt3CheckType string) (string, string, string) {
return basicInfo, securityInfo, nt3CheckType return basicInfo, securityInfo, nt3CheckType
} }
// CaptureOutput 捕获函数输出并返回字符串 // CaptureOutput 捕获函数输出和错误输出并返回字符串
func CaptureOutput(f func()) string { func CaptureOutput(f func()) string {
old := os.Stdout // 保存旧的 stdout 和 stderr
r, w, _ := os.Pipe() oldStdout := os.Stdout
os.Stdout = w oldStderr := os.Stderr
// 创建管道
stdoutPipeR, stdoutPipeW, err := os.Pipe()
if err != nil {
return "Error creating stdout pipe"
}
stderrPipeR, stderrPipeW, err := os.Pipe()
if err != nil {
stdoutPipeW.Close()
stdoutPipeR.Close()
return "Error creating stderr pipe"
}
// 替换标准输出和标准错误输出为管道写入端
os.Stdout = stdoutPipeW
os.Stderr = stderrPipeW
// 恢复标准输出和标准错误输出
defer func() {
os.Stdout = oldStdout
os.Stderr = oldStderr
stdoutPipeW.Close()
stderrPipeW.Close()
stdoutPipeR.Close()
stderrPipeR.Close()
}()
// 缓冲区
var stdoutBuf, stderrBuf bytes.Buffer
// 并发读取 stdout 和 stderr
done := make(chan struct{})
go func() {
io.Copy(&stdoutBuf, stdoutPipeR)
done <- struct{}{}
}()
go func() {
io.Copy(&stderrBuf, stderrPipeR)
done <- struct{}{}
}()
// 执行函数
f() f()
w.Close() // 关闭管道写入端,让管道读取端可以读取所有数据
os.Stdout = old stdoutPipeW.Close()
var buf bytes.Buffer stderrPipeW.Close()
buf.ReadFrom(r) // 等待两个 goroutine 完成
return buf.String() <-done
<-done
// 返回捕获的输出字符串
return stdoutBuf.String() + stderrBuf.String()
} }
// PrintAndCapture 捕获函数输出的同时打印内容 // PrintAndCapture 捕获函数输出的同时打印内容