From a1ae4f8e45832f3a4704efae2a139a3db7a7183e Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Tue, 31 Jan 2023 20:11:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=8C=87=E5=AE=9AIP?= =?UTF-8?q?=E6=AE=B5=E6=95=B0=E6=8D=AE(-ip)=20=E5=8F=82=E6=95=B0;=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E5=BB=B6=E8=BF=9F=E6=B5=8B=E9=80=9F?= =?UTF-8?q?=E6=97=B6=E6=98=BE=E7=A4=BA=E5=8F=AF=E7=94=A8=20IP=20=E6=95=B0?= =?UTF-8?q?=E9=87=8F;=20=E6=96=B0=E5=A2=9E=20=E6=9C=89=E6=95=88=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=BB=A3=E7=A0=81(HTTPing=20=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E6=89=80=E7=94=A8)=20=E5=8F=82=E6=95=B0;=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20HTTPing=20=E5=BB=B6=E8=BF=9F=E6=B5=8B=E9=80=9F=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F;=20=E4=BC=98=E5=8C=96=20=E5=8C=B9=E9=85=8D=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E5=9C=B0=E5=8C=BA=20=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 333 +++++++++++++++++++++++----------------------- task/download.go | 14 +- task/httping.go | 86 ++++++------ task/ip.go | 43 +++--- task/tcping.go | 4 +- utils/csv.go | 14 -- utils/progress.go | 2 +- 7 files changed, 248 insertions(+), 248 deletions(-) diff --git a/main.go b/main.go index c0a534d..276b6a2 100644 --- a/main.go +++ b/main.go @@ -1,164 +1,169 @@ -package main - -import ( - "flag" - "fmt" - "io/ioutil" - "net/http" - "os" - "runtime" - "time" - - "CloudflareSpeedTest/task" - "CloudflareSpeedTest/utils" -) - -var ( - version, versionNew string -) - -func init() { - var printVersion bool - var help = ` -CloudflareSpeedTest ` + version + ` -测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP (IPv4+IPv6)! -https://github.com/XIU2/CloudflareSpeedTest - -参数: - -n 200 - 测速线程数量;越多测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000) - -t 4 - 延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP;(默认 4 次) - -tp 443 - 指定测速端口;延迟测速/下载测速时使用的端口;(默认 443 端口,httping模式下该参数无效) - - -dn 10 - 下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10 个) - -dt 10 - 下载测速时间;单个 IP 下载测速最长时间,不能太短;(默认 10 秒) - -url https://cf.xiu2.xyz/url - 下载测速地址;用来下载测速的 Cloudflare CDN 文件地址,默认地址不保证可用性,建议自建; - - -tl 200 - 平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms) - -tll 40 - 平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 0 ms) - -sl 5 - 下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s) - - -p 10 - 显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 10 个) - -f ip.txt - IP段数据文件;如路径含有空格请加上引号;支持其他 CDN IP段;(默认 ip.txt) - -o result.csv - 写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv) - - -dd - 禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用) - -allip - 测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 IP 段随机测速一个 IP) - - -Httping - 启用HTTP ping;启用后会将tcping换成httping模式;(默认 不启用) - -HttpingColo DFW,LAX,SEA,SJC,FRA,MAD - 匹配机场三字码;需要匹配多个请使用英文逗号分割;(默认 匹配全部机场码,需要启用HTTP ping) - 目前已知区域:KIX,HKG,SIN,NRT,ICN,DFW,LAX,SEA,SJC,FRA,MAD - 目前已知大概率能扫描到美/法区域 - -HttpingTimeout 2000 - 指定httping超时时间;httping超时毫秒;(默认 2000 ms,需要启用HTTP ping) - -v - 打印程序版本 + 检查版本更新 - -h - 打印帮助说明 -` - var minDelay, maxDelay, downloadTime int - flag.IntVar(&task.Routines, "n", 200, "测速线程数量") - flag.IntVar(&task.PingTimes, "t", 4, "延迟测速次数") - flag.IntVar(&task.TCPPort, "tp", 443, "指定测速端口") - flag.IntVar(&task.TestCount, "dn", 10, "下载测速数量") - flag.IntVar(&downloadTime, "dt", 10, "下载测速时间") - flag.StringVar(&task.URL, "url", "https://cf.xiu2.xyz/url", "下载测速地址") - flag.IntVar(&maxDelay, "tl", 9999, "平均延迟上限") - flag.IntVar(&minDelay, "tll", 0, "平均延迟下限") - flag.Float64Var(&task.MinSpeed, "sl", 0, "下载速度下限") - flag.IntVar(&utils.PrintNum, "p", 10, "显示结果数量") - flag.StringVar(&task.IPFile, "f", "ip.txt", "IP 数据文件") - flag.StringVar(&utils.Output, "o", "result.csv", "输出结果文件") - flag.BoolVar(&task.Disable, "dd", false, "禁用下载测速") - flag.BoolVar(&task.TestAll, "allip", false, "测速全部 IP") - flag.BoolVar(&printVersion, "v", false, "打印程序版本") - flag.BoolVar(&task.Httping, "Httping", false, "启用HTTP ping") - flag.StringVar(&task.HttpingColo, "HttpingColo", "", "匹配机场三字码") - flag.IntVar(&task.HttpingTimeout, "HttpingTimeout", 2000, "指定httping超时时间") - flag.Usage = func() { fmt.Print(help) } - flag.Parse() - - if task.MinSpeed > 0 && time.Duration(maxDelay)*time.Millisecond == utils.InputMaxDelay { - fmt.Println("[小提示] 在使用 [-sl] 参数时,建议搭配 [-tl] 参数,以避免因凑不够 [-dn] 数量而一直测速...") - } - utils.InputMaxDelay = time.Duration(maxDelay) * time.Millisecond - utils.InputMinDelay = time.Duration(minDelay) * time.Millisecond - task.Timeout = time.Duration(downloadTime) * time.Second - task.HttpingColomap = task.MapColoMap() - task.HttpingRequest = task.GetRequest() - - if printVersion { - println(version) - fmt.Println("检查版本更新中...") - checkUpdate() - if versionNew != "" { - fmt.Printf("*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***", versionNew) - } else { - fmt.Println("当前为最新版本 [" + version + "]!") - } - os.Exit(0) - } -} - -func main() { - task.InitRandSeed() // 置随机数种子 - - fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version) - - // 开始延迟测速 - pingData := task.NewPing().Run().FilterDelay() - // 开始下载测速 - speedData := task.TestDownloadSpeed(pingData) - utils.ExportCsv(speedData) // 输出文件 - speedData.Print() // 打印结果 - - if versionNew != "" { - fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew) - } - endPrint() -} - -func endPrint() { - if utils.NoPrintResult() { - return - } - if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭) - fmt.Printf("按下 回车键 或 Ctrl+C 退出。") - fmt.Scanln() - } -} - -// 检查更新 -func checkUpdate() { - timeout := 10 * time.Second - client := http.Client{Timeout: timeout} - res, err := client.Get("https://api.xiu2.xyz/ver/cloudflarespeedtest.txt") - if err != nil { - return - } - // 读取资源数据 body: []byte - body, err := ioutil.ReadAll(res.Body) - if err != nil { - return - } - // 关闭资源流 - defer res.Body.Close() - if string(body) != version { - versionNew = string(body) - } -} +package main + +import ( + "flag" + "fmt" + "io/ioutil" + "net/http" + "os" + "runtime" + "time" + + "CloudflareSpeedTest/task" + "CloudflareSpeedTest/utils" +) + +var ( + version, versionNew string +) + +func init() { + var printVersion bool + var help = ` +CloudflareSpeedTest ` + version + ` +测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP (IPv4+IPv6)! +https://github.com/XIU2/CloudflareSpeedTest + +参数: + -n 200 + 延迟测速线程;越多延迟测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000) + -t 4 + 延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP;(默认 4 次) + -dn 10 + 下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10 个) + -dt 10 + 下载测速时间;单个 IP 下载测速最长时间,不能太短;(默认 10 秒) + -tp 443 + 指定测速端口;延迟测速/下载测速时使用的端口;(默认 443 端口) + -url https://cf.xiu2.xyz/url + 指定测速地址;延迟测速(HTTPing)/下载测速时使用的地址,默认地址不保证可用性,建议自建; + + -httping + 切换测速模式;延迟测速模式改为 HTTP 协议,所用测试地址为 [-url] 参数;(默认 TCPing) + -httping-code 200 + 有效状态代码;HTTPing 延迟测速时网页返回的有效 HTTP 状态码,仅限一个;(默认 200 301 302) + -cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD + 匹配指定地区;地区名为当地机场三字码,英文逗号分隔,仅 HTTPing 模式可用;(默认 所有地区) + + -tl 200 + 平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms) + -tll 40 + 平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 0 ms) + -sl 5 + 下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s) + + -p 10 + 显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 10 个) + -f ip.txt + IP段数据文件;如路径含有空格请加上引号;支持其他 CDN IP段;(默认 ip.txt) + -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32 + 指定IP段数据;直接通过参数指定要测速的 IP 段数据,英文逗号分隔;(默认 空) + -o result.csv + 写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv) + + -dd + 禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用) + -allip + 测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 /24 段随机测速一个 IP) + + -v + 打印程序版本 + 检查版本更新 + -h + 打印帮助说明 +` + var minDelay, maxDelay, downloadTime int + flag.IntVar(&task.Routines, "n", 200, "延迟测速线程") + flag.IntVar(&task.PingTimes, "t", 4, "延迟测速次数") + flag.IntVar(&task.TestCount, "dn", 10, "下载测速数量") + flag.IntVar(&downloadTime, "dt", 10, "下载测速时间") + flag.IntVar(&task.TCPPort, "tp", 443, "指定测速端口") + flag.StringVar(&task.URL, "url", "https://cf.xiu2.xyz/url", "指定测速地址") + + flag.BoolVar(&task.Httping, "httping", false, "切换测速模式") + flag.IntVar(&task.HttpingStatusCode, "httping-code", 0, "有效状态代码") + flag.StringVar(&task.HttpingCFColo, "cfcolo", "", "匹配指定地区") + + flag.IntVar(&maxDelay, "tl", 9999, "平均延迟上限") + flag.IntVar(&minDelay, "tll", 0, "平均延迟下限") + flag.Float64Var(&task.MinSpeed, "sl", 0, "下载速度下限") + + flag.IntVar(&utils.PrintNum, "p", 10, "显示结果数量") + flag.StringVar(&task.IPFile, "f", "ip.txt", "IP段数据文件") + flag.StringVar(&task.IPText, "ip", "", "指定IP段数据") + flag.StringVar(&utils.Output, "o", "result.csv", "输出结果文件") + + flag.BoolVar(&task.Disable, "dd", false, "禁用下载测速") + flag.BoolVar(&task.TestAll, "allip", false, "测速全部 IP") + + flag.BoolVar(&printVersion, "v", false, "打印程序版本") + flag.Usage = func() { fmt.Print(help) } + flag.Parse() + + if task.MinSpeed > 0 && time.Duration(maxDelay)*time.Millisecond == utils.InputMaxDelay { + fmt.Println("[小提示] 在使用 [-sl] 参数时,建议搭配 [-tl] 参数,以避免因凑不够 [-dn] 数量而一直测速...") + } + utils.InputMaxDelay = time.Duration(maxDelay) * time.Millisecond + utils.InputMinDelay = time.Duration(minDelay) * time.Millisecond + task.Timeout = time.Duration(downloadTime) * time.Second + task.HttpingCFColomap = task.MapColoMap() + + if printVersion { + println(version) + fmt.Println("检查版本更新中...") + checkUpdate() + if versionNew != "" { + fmt.Printf("*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***", versionNew) + } else { + fmt.Println("当前为最新版本 [" + version + "]!") + } + os.Exit(0) + } +} + +func main() { + task.InitRandSeed() // 置随机数种子 + + fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version) + + // 开始延迟测速 + pingData := task.NewPing().Run().FilterDelay() + // 开始下载测速 + speedData := task.TestDownloadSpeed(pingData) + utils.ExportCsv(speedData) // 输出文件 + speedData.Print() // 打印结果 + + if versionNew != "" { + fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew) + } + endPrint() +} + +func endPrint() { + if utils.NoPrintResult() { + return + } + if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭) + fmt.Printf("按下 回车键 或 Ctrl+C 退出。") + fmt.Scanln() + } +} + +// 检查更新 +func checkUpdate() { + timeout := 10 * time.Second + client := http.Client{Timeout: timeout} + res, err := client.Get("https://api.xiu2.xyz/ver/cloudflarespeedtest.txt") + if err != nil { + return + } + // 读取资源数据 body: []byte + body, err := ioutil.ReadAll(res.Body) + if err != nil { + return + } + // 关闭资源流 + defer res.Body.Close() + if string(body) != version { + versionNew = string(body) + } +} diff --git a/task/download.go b/task/download.go index 7cb4969..a6456ba 100644 --- a/task/download.go +++ b/task/download.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "sort" + "strconv" "time" "CloudflareSpeedTest/utils" @@ -24,11 +25,8 @@ const ( ) var ( - // download test url - URL = defaultURL - // download timeout + URL = defaultURL Timeout = defaultTimeout - // disable download Disable = defaultDisableDownload TestCount = defaultTestNum @@ -68,7 +66,13 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSe } fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s,下载测速数量:%d,下载测速队列:%d):\n", MinSpeed, TestCount, testNum) - bar := utils.NewBar(TestCount, "", "") + // 控制 下载测速进度条 与 延迟测速进度条 长度一致(强迫症) + bar_a := len(strconv.Itoa(len(ipSet))) + bar_b := " " + for i := 0; i < bar_a; i++ { + bar_b += " " + } + bar := utils.NewBar(TestCount, bar_b, "") for i := 0; i < testNum; i++ { speed := downloadHandler(ipSet[i].IP) ipSet[i].DownloadSpeed = speed diff --git a/task/httping.go b/task/httping.go index da18b6a..e722b0d 100644 --- a/task/httping.go +++ b/task/httping.go @@ -1,8 +1,8 @@ package task import ( - "crypto/tls" - "fmt" + //"crypto/tls" + //"fmt" "io" "log" "net" @@ -10,42 +10,31 @@ import ( "strings" "sync" "time" - - "CloudflareSpeedTest/utils" ) var ( - Httping bool //是否启用httping - HttpingTimeout int //设置超时时间,单位毫秒 - HttpingColo string //有值代表筛选机场三字码区域 -) - -var ( - HttpingColomap *sync.Map - HttpingRequest *http.Request + Httping bool + HttpingStatusCode int + HttpingCFColo string + HttpingCFColomap *sync.Map ) // pingReceived pingTotalTime func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration) { - var fullAddress string - if isIPv4(ip.String()) { - fullAddress = fmt.Sprintf("%s", ip.String()) - } else { - fullAddress = fmt.Sprintf("[%s]", ip.String()) - } hc := http.Client{ - Timeout: time.Duration(HttpingTimeout) * time.Millisecond, + Timeout: time.Second * 2, Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + DialContext: getDialContext(ip), + //TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 跳过证书验证 }, - } // #nosec + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse // 阻止重定向 + }, + } - traceURL := fmt.Sprintf("http://%s/cdn-cgi/trace", - fullAddress) - - // for connect and get colo + // 先访问一次获得 HTTP 状态码 及 Cloudflare Colo { - requ, err := http.NewRequest(http.MethodHead, traceURL, nil) + requ, err := http.NewRequest(http.MethodHead, URL, nil) if err != nil { return 0, 0 } @@ -55,22 +44,35 @@ func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration) { return 0, 0 } defer resp.Body.Close() + + //fmt.Println("IP:", ip, "StatusCode:", resp.StatusCode, resp.Request.URL) + if HttpingStatusCode == 0 || HttpingStatusCode < 100 && HttpingStatusCode > 599 { + if resp.StatusCode != 200 && resp.StatusCode != 301 && resp.StatusCode != 302 { + return 0, 0 + } + } else { + if resp.StatusCode != HttpingStatusCode { + return 0, 0 + } + } + io.Copy(io.Discard, resp.Body) - cfRay := resp.Header.Get("CF-RAY") - - colo := p.getColo(cfRay) - if colo == "" { - return 0, 0 + if HttpingCFColo != "" { + cfRay := resp.Header.Get("CF-RAY") + colo := p.getColo(cfRay) + if colo == "" { + return 0, 0 + } } } - // for test delay + // 循环测速计算延迟 success := 0 var delay time.Duration for i := 0; i < PingTimes; i++ { - requ, err := http.NewRequest(http.MethodHead, traceURL, nil) + requ, err := http.NewRequest(http.MethodHead, URL, nil) if err != nil { log.Fatal("意外的错误,情报告:", err) return 0, 0 @@ -97,11 +99,11 @@ func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration) { } func MapColoMap() *sync.Map { - if HttpingColo == "" { + if HttpingCFColo == "" { return nil } - colos := strings.Split(HttpingColo, ",") + colos := strings.Split(HttpingCFColo, ",") colomap := &sync.Map{} for _, colo := range colos { colomap.Store(colo, colo) @@ -109,14 +111,6 @@ func MapColoMap() *sync.Map { return colomap } -func GetRequest() *http.Request { - req, err := http.NewRequest("GET", URL, nil) - if err != nil { - log.Fatal(err) - } - return req -} - func (p *Ping) getColo(b string) string { if b == "" { return "" @@ -125,13 +119,11 @@ func (p *Ping) getColo(b string) string { out := idColo[1] - utils.ColoAble.Store(out, out) - - if HttpingColomap == nil { + if HttpingCFColomap == nil { return out } - _, ok := HttpingColomap.Load(out) + _, ok := HttpingCFColomap.Load(out) if ok { return out } diff --git a/task/ip.go b/task/ip.go index 0d1b3d0..cc57b5a 100644 --- a/task/ip.go +++ b/task/ip.go @@ -18,6 +18,7 @@ var ( TestAll = false // IPFile is the filename of IP Rangs IPFile = defaultInputFile + IPText string ) func InitRandSeed() { @@ -137,22 +138,34 @@ func (r *IPRanges) chooseIPv6() { } func loadIPRanges() []*net.IPAddr { - if IPFile == "" { - IPFile = defaultInputFile - } - file, err := os.Open(IPFile) - if err != nil { - log.Fatal(err) - } - defer file.Close() ranges := newIPRanges() - scanner := bufio.NewScanner(file) - for scanner.Scan() { - ranges.parseCIDR(scanner.Text()) - if isIPv4(scanner.Text()) { - ranges.chooseIPv4() - } else { - ranges.chooseIPv6() + if IPText != "" { // 从参数中获取 IP 段数据 + IPs := strings.Split(IPText, ",") + for _, IP := range IPs { + ranges.parseCIDR(IP) + if isIPv4(IP) { + ranges.chooseIPv4() + } else { + ranges.chooseIPv6() + } + } + } else { // 从文件中获取 IP 段数据 + if IPFile == "" { + IPFile = defaultInputFile + } + file, err := os.Open(IPFile) + if err != nil { + log.Fatal(err) + } + defer file.Close() + scanner := bufio.NewScanner(file) + for scanner.Scan() { + ranges.parseCIDR(scanner.Text()) + if isIPv4(scanner.Text()) { + ranges.chooseIPv4() + } else { + ranges.chooseIPv6() + } } } return ranges.ips diff --git a/task/tcping.go b/task/tcping.go index 16e9f76..1ba8177 100644 --- a/task/tcping.go +++ b/task/tcping.go @@ -55,7 +55,7 @@ func NewPing() *Ping { ips: ips, csv: make(utils.PingDelaySet, 0), control: make(chan bool, Routines), - bar: utils.NewBar(len(ips), "可用IP:", ""), + bar: utils.NewBar(len(ips), "可用:", ""), } } @@ -64,7 +64,7 @@ func (p *Ping) Run() utils.PingDelaySet { return p.csv } if Httping { - fmt.Printf("开始延迟测速(模式:HTTP,端口:80,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds()) + fmt.Printf("开始延迟测速(模式:HTTP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds()) } else { fmt.Printf("开始延迟测速(模式:TCP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds()) } diff --git a/utils/csv.go b/utils/csv.go index d730dc2..0af80fd 100644 --- a/utils/csv.go +++ b/utils/csv.go @@ -6,10 +6,7 @@ import ( "log" "net" "os" - "sort" "strconv" - "strings" - "sync" "time" ) @@ -24,7 +21,6 @@ var ( InputMinDelay = minDelay Output = defaultOutput PrintNum = 10 - ColoAble sync.Map ) // 是否打印测试结果 @@ -143,16 +139,6 @@ func (s DownloadSpeedSet) Swap(i, j int) { } func (s DownloadSpeedSet) Print() { - var colos []string - ColoAble.Range(func(key, value interface{}) bool { - colos = append(colos, key.(string)) - return true - }) - if len(colos) != 0 { - sort.Strings(colos) - colostrings := strings.Join(colos, ",") - fmt.Println("\n下次可以考虑机场三字码参数:" + colostrings + "\n") - } if NoPrintResult() { return } diff --git a/utils/progress.go b/utils/progress.go index bc7ef66..7d5b7f5 100644 --- a/utils/progress.go +++ b/utils/progress.go @@ -11,7 +11,7 @@ type Bar struct { } func NewBar(count int, MyStrStart, MyStrEnd string) *Bar { - tmpl := fmt.Sprintf(`{{counters . }}{{ bar . "[" "-" (cycle . "↖" "↗" "↘" "↙" ) "_" "]"}} %s {{string . "MyStr" | green}} %s `, MyStrStart, MyStrEnd) + tmpl := fmt.Sprintf(`{{counters . }} {{ bar . "[" "-" (cycle . "↖" "↗" "↘" "↙" ) "_" "]"}} %s {{string . "MyStr" | green}} %s `, MyStrStart, MyStrEnd) bar := pb.ProgressBarTemplate(tmpl).Start(count) return &Bar{pb: bar} }