v1.2.2 新增自定义输出结果文件功能等

This commit is contained in:
xiu2
2020-09-01 17:45:18 +08:00
parent 31743a8138
commit 383f4c979b
3 changed files with 23 additions and 10 deletions

View File

@@ -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

16
main.go
View File

@@ -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) // 输出结果
}

View File

@@ -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()