runSingleSpeedTest 单 IP 测速
(useTLS bool)
| 437 | |
| 438 | // runSingleSpeedTest 单 IP 测速 |
| 439 | func runSingleSpeedTest(useTLS bool) { |
| 440 | scanner := bufio.NewScanner(os.Stdin) |
| 441 | |
| 442 | fmt.Print("请输入需要测速的 IP: ") |
| 443 | if !scanner.Scan() { |
| 444 | return |
| 445 | } |
| 446 | ip := strings.TrimSpace(scanner.Text()) |
| 447 | |
| 448 | defaultPort := 80 |
| 449 | if useTLS { |
| 450 | defaultPort = 443 |
| 451 | } |
| 452 | |
| 453 | fmt.Printf("请输入需要测速的端口 (默认%d): ", defaultPort) |
| 454 | var port int |
| 455 | if scanner.Scan() { |
| 456 | input := strings.TrimSpace(scanner.Text()) |
| 457 | if input == "" { |
| 458 | port = defaultPort |
| 459 | } else { |
| 460 | val, err := strconv.Atoi(input) |
| 461 | if err != nil || val <= 0 { |
| 462 | fmt.Printf("输入无效,已使用默认端口 %d\n", defaultPort) |
| 463 | port = defaultPort |
| 464 | } else { |
| 465 | port = val |
| 466 | } |
| 467 | } |
| 468 | } else { |
| 469 | port = defaultPort |
| 470 | } |
| 471 | |
| 472 | fmt.Printf("正在测速 %s 端口 %d\n", ip, port) |
| 473 | |
| 474 | speedKB, tcpMs, dc := runSpeedTestSimple(ip, port, useTLS) |
| 475 | if dc != "" { |
| 476 | fmt.Printf("%s 平均速度 %d kB/s, TCP延迟 %dms, 数据中心=%s\n", ip, speedKB, tcpMs, lookupDataCenter(dc)) |
| 477 | } else { |
| 478 | fmt.Printf("%s 平均速度 %d kB/s, TCP延迟 %dms\n", ip, speedKB, tcpMs) |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | // clearCache 清空缓存,删除所有数据文件,下次运行重新下载 |
| 483 | func clearCache() { |
no test coverage detected