MCPcopy
hub / github.com/badafans/better-cloudflare-ip / runIPSelector

Function runIPSelector

main.go:79–140  ·  view source on GitHub ↗

runIPSelector 运行 IP 优选流程

(ipType int, useTLS bool)

Source from the content-addressed store, hash-verified

77
78// runIPSelector 运行 IP 优选流程
79func runIPSelector(ipType int, useTLS bool) {
80 var bandwidth int
81 var taskNum int
82
83 fmt.Print("请设置期望的带宽大小 (默认最小 1,单位 Mbps): ")
84 scanner := bufio.NewScanner(os.Stdin)
85 if scanner.Scan() {
86 input := strings.TrimSpace(scanner.Text())
87 if input == "" {
88 bandwidth = 1
89 } else {
90 val, err := strconv.Atoi(input)
91 if err != nil || val <= 0 {
92 fmt.Println("输入无效,已使用默认值 1 Mbps")
93 bandwidth = 1
94 } else {
95 bandwidth = val
96 }
97 }
98 }
99
100 fmt.Print("请设置 RTT 测试进程数 (默认 50,最大 100): ")
101 if scanner.Scan() {
102 input := strings.TrimSpace(scanner.Text())
103 if input == "" {
104 taskNum = 50
105 } else {
106 val, err := strconv.Atoi(input)
107 if err != nil {
108 fmt.Println("输入无效,已使用默认值 50")
109 taskNum = 50
110 } else if val <= 0 {
111 fmt.Println("进程数不能为 0,自动设置为默认值")
112 taskNum = 50
113 } else {
114 taskNum = val
115 }
116 if taskNum > 100 {
117 fmt.Println("超过最大进程限制,自动设置为最大值")
118 taskNum = 100
119 }
120 }
121 }
122
123 speed := bandwidth * 128
124 startTime := time.Now()
125
126 // 执行 Cloudflare 测试
127 anycast, max, avgms, dataCenter := cloudflareTest(ipType, useTLS, taskNum, speed)
128
129 realBandwidth := max / 128
130 endTime := time.Now()
131
132 fmt.Println()
133 fmt.Println("优选 IP:", anycast)
134 fmt.Println("设置带宽:", bandwidth, "Mbps")
135 fmt.Println("实测带宽:", realBandwidth, "Mbps")
136 fmt.Println("峰值速度:", max, "kB/s")

Callers 1

showMenuFunction · 0.85

Calls 1

cloudflareTestFunction · 0.85

Tested by

no test coverage detected