新增 下载速度排序;修复 下载测速时间 -dt 参数自定义值无效的问题;回调 下载测速时间默认值为 10 秒

This commit is contained in:
xiu2 2020-12-19 09:54:18 +08:00
parent f9ac05a072
commit 6c1166fc5e
3 changed files with 50 additions and 24 deletions

View File

@ -9,7 +9,7 @@
国外很多网站都在使用 Cloudflare CDN但分配给中国访客的 IP 并不友好。
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,所以就有了这个软件。
该软件可以**测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**!觉得好用请**点个⭐鼓励一下下~**
该软件可以**批量测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**!觉得好用请**点个⭐鼓励一下下~**
> 本项目也**适用于其他 CDN**,但是需要自行寻找 **CDN IP 段及下载测速地址**(否则只能延迟测速)。
@ -31,28 +31,29 @@
```
IP 地址 已发送 已接收 丢包率 平均延迟 下载速度 (MB/s)
104.27.198.101 4 4 0.00 126.52 12.71
104.22.43.157 4 4 0.00 129.38 16.74
104.27.214.140 4 4 0.00 132.02 4.65
104.22.42.165 4 4 0.00 133.63 12.00
104.22.35.177 4 4 0.00 135.75 3.92
104.22.87.44 4 4 0.00 136.00 5.86
104.22.67.122 4 4 0.00 136.50 9.47
104.22.88.154 4 4 0.00 140.75 13.00
104.22.69.218 4 4 0.00 142.00 19.07
104.27.184.10 4 4 0.00 148.02 21.05
104.27.200.69 4 4 0.00 146.23 28.64
172.67.60.78 4 4 0.00 139.82 15.02
104.25.140.153 4 4 0.00 146.49 14.90
104.27.192.65 4 4 0.00 140.28 14.07
172.67.62.214 4 4 0.00 139.29 12.71
104.27.207.5 4 4 0.00 145.92 11.95
172.67.54.193 4 4 0.00 146.71 11.55
104.22.66.8 4 4 0.00 147.42 11.11
104.27.197.63 4 4 0.00 131.29 10.26
172.67.58.91 4 4 0.00 140.19 9.14
...
```
选择一个平均延迟与下载速度都不错的 IP,至于拿来干嘛?取决于你~
测速结果第一行是**兼顾平均延迟与下载速度的最快 IP**,至于拿来干嘛?取决于你~
完整结果保存在当前目录下的 `result.csv` 文件中,用**记事本/表格软件**打开,排序为**延迟由低到高**,分别是
完整结果保存在当前目录下的 `result.csv` 文件中,用**记事本/表格软件**打开,格式如下
```
IP 地址, 已发送, 已接收, 丢包率, 平均延迟, 下载速度 (MB/s)
104.27.198.101, 4, 4, 0.00, 126.52, 12.71
104.27.200.69, 4, 4, 0.00, 146.23, 28.64
```
> 大家可以按照自己的需求,对完整结果**进一步筛选处理**,或者去看一看进阶使用(如设定测速条件)!
> 大家可以按自己需求,对完整结果**进一步筛选处理**,或者去看一看进阶使用**指定过滤条件**
****
## 进阶使用
@ -90,7 +91,7 @@ https://github.com/XIU2/CloudflareSpeedTest
-o result.csv
输出结果文件;如含有空格请加上引号;为空格时不输出结果文件(-o " ");允许其他后缀;(默认 result.csv)
-dd
禁用下载测速;如果带上该参数就是禁用下载速;(默认 启用)
禁用下载测速;禁用后测速结果会按延迟排序(默认按下载速度排序)(默认 启用)
-ipv6
IPv6 测速模式;请确保 IP 数据文件内只包含 IPv6 IP段软件不支持同时测速 IPv4+IPv6(默认 IPv4)
-allip
@ -118,6 +119,8 @@ CloudflareST.exe -p 0 -f ip.txt -dd
# 指定 IPv6 数据文件( ipv6.txt ),不显示结果直接退出(-p 值为 0
CloudflareST.exe -p 0 -f ipv6.txt -dd -ipv6
# ——————————————————————
# 指定 IPv4 数据文件,不输出结果到文件,直接显示结果(-p 值为 10 条)
CloudflareST.exe -p 10 -f ip.txt -o " " -dd
@ -127,9 +130,13 @@ CloudflareST.exe -f ip.txt -o result.csv -dd
# 指定 IPv4 数据文件 及 输出结果到文件(绝对路径,即 C:\abc\ 目录下,如果包含空格请加上引号)
CloudflareST.exe -f C:\abc\ip.txt -o C:\abc\result.csv -dd
# ——————————————————————
# 指定下载测速地址(要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN如果包含空格请加上引号
CloudflareST.exe -url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
# ——————————————————————
# 指定测速条件(只有同时满足三个条件时才会停止测速):
# 延迟时间上限200 ms下载速度下限0 MB/s数量10 个
CloudflareST.exe -tl 200 -dn 10

19
main.go
View File

@ -17,10 +17,9 @@ import (
var version, ipFile, outputFile, versionNew string
var disableDownload, ipv6Mode, allip bool
var tcpPort, printResultNum, timeLimit, speedLimit int
var tcpPort, printResultNum, timeLimit, speedLimit, downloadSecond int
func init() {
var downloadSecond int64
var printVersion bool
var help = `
CloudflareSpeedTest ` + version + `
@ -36,8 +35,8 @@ https://github.com/XIU2/CloudflareSpeedTest
延迟测速端口延迟测速 TCP 协议的端口(默认 443)
-dn 20
下载测速数量延迟测速并排序后从最低延迟起下载测速数量请勿太多(速度慢)(默认 20)
-dt 5
下载测速时间单个 IP 测速最长时间单位(默认 5)
-dt 10
下载测速时间单个 IP 测速最长时间单位(默认 10)
-url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
下载测速地址用来 Cloudflare CDN 测速的文件地址如含有空格请加上引号
-tl 200
@ -51,7 +50,7 @@ https://github.com/XIU2/CloudflareSpeedTest
-o result.csv
输出结果文件如含有空格请加上引号为空格时不输出结果文件(-o " ")允许其他后缀(默认 result.csv)
-dd
禁用下载测速如果带上该参数将会禁用下载测速(默认 启用下载测速)
禁用下载测速禁用后测速结果会按延迟排序默认按下载速度排序(默认 启用下载测速)
-ipv6
IPv6 测速模式请确保 IP 数据文件内只包含 IPv6 IP段软件不支持同时测速 IPv4+IPv6(默认 IPv4)
-allip
@ -66,7 +65,7 @@ https://github.com/XIU2/CloudflareSpeedTest
flag.IntVar(&pingTime, "t", 4, "延迟测速次数")
flag.IntVar(&tcpPort, "tp", 443, "延迟测速端口")
flag.IntVar(&downloadTestCount, "dn", 20, "下载测速数量")
flag.Int64Var(&downloadSecond, "dt", 5, "下载测速时间")
flag.IntVar(&downloadSecond, "dt", 10, "下载测速时间")
flag.StringVar(&url, "url", "https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png", "下载测速地址")
flag.IntVar(&timeLimit, "tl", 0, "延迟时间上限")
flag.IntVar(&speedLimit, "sl", 0, "下载速度下限")
@ -78,8 +77,6 @@ https://github.com/XIU2/CloudflareSpeedTest
flag.StringVar(&outputFile, "o", "result.csv", "输出结果文件")
flag.BoolVar(&printVersion, "v", false, "打印程序版本")
downloadTestTime = time.Duration(downloadSecond) * time.Second
flag.Usage = func() { fmt.Print(help) }
flag.Parse()
if printVersion {
@ -139,6 +136,11 @@ func main() {
var mu sync.Mutex
var data = make([]CloudflareIPData, 0)
var data_2 = make([]CloudflareIPData, 0)
downloadTestTime = time.Duration(downloadSecond) * time.Second
//println(downloadTestCount)
//println(downloadTestTime)
//println(downloadSecond)
fmt.Println("# XIU2/CloudflareSpeedTest " + version + "\n")
if ipv6Mode {
@ -194,6 +196,7 @@ func main() {
}
if len(data_2) > 0 { // 如果该数字有内容,说明进行过指定条件的下载测速
sort.Sort(CloudflareIPDataSetD(data_2)) // 排序
if outputFile != "" {
ExportCsv(outputFile, data_2) // 输出结果到文件(指定延迟时间或下载速度的)
}

16
util.go
View File

@ -85,8 +85,12 @@ const tcpConnectTimeout = time.Second * 1
var failTime int
// 平均延迟排序(丢包另算)
type CloudflareIPDataSet []CloudflareIPData
// 下载速度排序
type CloudflareIPDataSetD []CloudflareIPData
func initRandSeed() {
rand.Seed(time.Now().UnixNano())
}
@ -146,3 +150,15 @@ func (cfs CloudflareIPDataSet) Less(i, j int) bool {
func (cfs CloudflareIPDataSet) Swap(i, j int) {
cfs[i], cfs[j] = cfs[j], cfs[i]
}
func (cfs CloudflareIPDataSetD) Len() int {
return len(cfs)
}
func (cfs CloudflareIPDataSetD) Less(i, j int) bool {
return cfs[i].downloadSpeed > cfs[j].downloadSpeed
}
func (cfs CloudflareIPDataSetD) Swap(i, j int) {
cfs[i], cfs[j] = cfs[j], cfs[i]
}