From 383f4c979bd0c97590e923a4af703d136cf9e7e4 Mon Sep 17 00:00:00 2001 From: xiu2 <54703944+XIU2@users.noreply.github.com> Date: Tue, 1 Sep 2020 17:45:18 +0800 Subject: [PATCH] =?UTF-8?q?v1.2.2=20=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=BE=93=E5=87=BA=E7=BB=93=E6=9E=9C=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 13 ++++++++++--- main.go | 16 ++++++++++++---- util.go | 4 +--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index abe85eb..4e48bc3 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,9 @@ https://github.com/XIU2/CloudflareSpeedTest -dt 10 下载测速时间;单个 IP 测速最长时间,单位:秒;(默认 10) -f ip.txt - IP 数据文件;支持相对路径和绝对路径,如果包含空格请前后加上引号;(默认 ip.txt) + IP 数据文件;相对/绝对路径,如包含空格请加上引号;支持其他 CDN IP段,记得禁用下载测试;(默认 ip.txt) + -o result.csv + 输出结果文件;相对/绝对路径,如包含空格请加上引号;允许 .txt 等后缀;(默认 result.csv) -dd 禁用下载测速;如果带上该参数就是禁用下载测速;(默认 启用) -v @@ -55,8 +57,9 @@ https://github.com/XIU2/CloudflareSpeedTest 打印帮助说明 示例: - CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 - CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "C:\abc\ip.txt" -dd + CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 + CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "ip.txt" -o "result.csv" -dd + CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "C:\abc\ip.txt" -o "C:\abc\result.csv" -dd ``` #### 使用示例 @@ -67,6 +70,10 @@ https://github.com/XIU2/CloudflareSpeedTest ``` cmd # CMD 示例 CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 +# 指定 IP数据文件 及 输出结果文件(相对路径,即当前目录下) +CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "ip.txt" -o "result.csv" -dd +# 指定 IP数据文件 及 输出结果文件(绝对路径,即 C:\abc\ 目录下) +CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "C:\abc\ip.txt" -o "C:\abc\result.csv" -dd ``` ``` cmd diff --git a/main.go b/main.go index 8a8a6d4..8f5a22f 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( var version string var disableDownload bool var ipFile string +var outputFile string func init() { var downloadSecond int64 @@ -33,7 +34,9 @@ https://github.com/XIU2/CloudflareSpeedTest -dt 10 下载测速时间;单个 IP 测速最长时间,单位:秒;(默认 10) -f ip.txt - IP 数据文件;支持相对路径和绝对路径,如果包含空格请前后加上引号;(默认 ip.txt) + IP 数据文件;相对/绝对路径,如包含空格请加上引号;支持其他 CDN IP段,记得禁用下载测试;(默认 ip.txt) + -o result.csv + 输出结果文件;相对/绝对路径,如包含空格请加上引号;允许 .txt 等后缀;(默认 result.csv) -dd 禁用下载测速;如果带上该参数就是禁用下载测速;(默认 启用) -v @@ -42,8 +45,9 @@ https://github.com/XIU2/CloudflareSpeedTest 打印帮助说明 示例: - CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 - CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "C:\abc\ip.txt" -dd` + CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 + CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "ip.txt" -o "result.csv" -dd + CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "C:\abc\ip.txt" -o "C:\abc\result.csv" -dd` flag.IntVar(&pingRoutine, "n", 500, "测速线程数量") flag.IntVar(&pingTime, "t", 4, "延迟测速次数") @@ -51,6 +55,7 @@ https://github.com/XIU2/CloudflareSpeedTest flag.Int64Var(&downloadSecond, "dt", 10, "下载测速时间") flag.BoolVar(&disableDownload, "dd", false, "禁用下载测速") flag.StringVar(&ipFile, "f", "ip.txt", "IP 数据文件") + flag.StringVar(&outputFile, "o", "result.csv", "输出结果文件") flag.BoolVar(&printVersion, "v", false, "打印程序版本") downloadTestTime = time.Duration(downloadSecond) * time.Second @@ -76,6 +81,9 @@ https://github.com/XIU2/CloudflareSpeedTest if ipFile == "" { ipFile = "ip.txt" } + if outputFile == "" { + outputFile = "result.csv" + } } func main() { @@ -118,5 +126,5 @@ func main() { fmt.Println("\n[信息] IP数量为 0,跳过下载测速。") } } - ExportCsv("./result.csv", data) // 输出结果 + ExportCsv(outputFile, data) // 输出结果 } diff --git a/util.go b/util.go index baaad28..82f9e24 100644 --- a/util.go +++ b/util.go @@ -36,13 +36,11 @@ func ExportCsv(filePath string, data []CloudflareIPData) { } defer fp.Close() w := csv.NewWriter(fp) //创建一个新的写入文件流 - w.Write([]string{"IP 地址", "Ping 发送次数", "Ping 接收次数", "Ping 接收率", "平均延迟", "下载速度 (MB/s)"}) + w.Write([]string{"IP 地址", "测试次数", "成功次数", "成功比率", "平均延迟", "下载速度 (MB/s)"}) w.WriteAll(convertToString(data)) w.Flush() } -//"IP Address","Ping Count","Ping received","Ping received rate","Ping time","Download speed" - func (cf *CloudflareIPData) toString() []string { result := make([]string, 6) result[0] = cf.ip.String()