29 Commits

Author SHA1 Message Date
xiu2
7212110dde 优化 IPv6 测速功能(支持 /128 子网掩码) 2021-09-23 19:16:08 +08:00
xiu2
d651fdeb54 新增 ipall.txt(完整版的 IPv4 数据文件,没有过滤不可用的 IP) 2021-08-29 09:07:42 +08:00
xiu2
d453124943 README.md 2021-08-27 09:41:30 +08:00
xiu2
e92badf8be 调低 [测速线程数量] 默认值为 200 2021-08-26 20:43:22 +08:00
xiu2
01dc5df491 README.md 2021-08-20 11:37:08 +08:00
xiu2
b428775cc5 README.md 2021-08-16 13:42:43 +08:00
xiu2
5202f73108 README.md 2021-08-11 11:52:39 +08:00
xiu2
1bb45af3f1 README.md 2021-08-11 11:03:03 +08:00
xiu2
3736d81dda README.md 2021-08-11 10:48:12 +08:00
xiu2
a42059737b 新增 [平均延迟下限] 参数(用于过滤被假蔷的 IP) 2021-08-11 10:46:36 +08:00
xiu2
46da45b25f 新增 [平均延迟下限] 参数(用于过滤被假蔷的 IP) 2021-08-11 10:37:59 +08:00
xiu2
acd47ee96d README.md 2021-08-10 01:14:08 +08:00
xiu2
698108f453 优化 文本显示 2021-07-24 13:45:11 +08:00
xiu2
2963b61910 README.md 2021-07-22 19:20:39 +08:00
xiu2
9bab2944b1 README.md 2021-07-17 07:21:54 +08:00
xiu2
fa5e4f34f0 README.md 2021-07-04 08:04:59 +08:00
xiu2
db9d092010 README.md 2021-07-01 14:34:53 +08:00
xiu2
180097b044 删除 多余的空格 2021-04-09 12:53:45 +08:00
xiu2
c115249811 更新 ip.txt(官方改动) 2021-04-09 07:23:04 +08:00
xiu2
3b7851f77c README.md 2021-04-03 10:19:26 +08:00
xiu2
80c201f160 README.md 2021-03-21 21:00:03 +08:00
xiu2
85546abb23 新增 测速单个 IP 时可以省略 /32 子网掩码(允许和 IP 段混杂使用) 2021-03-19 21:43:29 +08:00
xiu2
1d46334a6b 移除 ip.txt 中不可用的 IP 段(约占三分之一,如回源 IP) 2021-03-16 20:57:26 +08:00
xiu2
afd8736268 README.md 2021-03-13 09:35:26 +08:00
xiu2
17ff85954f README.md 2021-03-13 09:34:22 +08:00
xiu2
7ece9d6cda README.md 2021-02-18 23:51:05 +08:00
xiu2
d67b9bc86d README.md 2021-02-18 23:48:07 +08:00
xiu2
73ae874645 README.md 2021-02-18 23:47:11 +08:00
xiu2
0441c27cec README.md 2021-02-18 23:39:37 +08:00
5 changed files with 163 additions and 75 deletions

View File

@@ -64,6 +64,13 @@ func loadFirstIPOfRangeFromFile(ipFile string) []net.IPAddr {
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
IPString := scanner.Text()
if !strings.Contains(IPString, "/") { // 如果不含有 / 则代表不是 IP 段,而是一个单独的 IP因此需要加上 /32 /128 子网掩码
if ipv6Mode {
IPString += "/128"
} else {
IPString += "/32"
}
}
firstIP, IPRange, err := net.ParseCIDR(IPString)
//fmt.Println(firstIP)
//fmt.Println(IPRange)
@@ -71,9 +78,9 @@ func loadFirstIPOfRangeFromFile(ipFile string) []net.IPAddr {
log.Fatal(err)
}
if !ipv6Mode { // IPv4
minIP, maxIP := getCidrIPRange(scanner.Text()) // 获取 IP 最后一段最小值和最大值
Mask, _ := strconv.Atoi(strings.Split(scanner.Text(), "/")[1]) // 获取子网掩码
MaxIPNum := getCidrHostNum(Mask) // 根据子网掩码获取主机数量
minIP, maxIP := getCidrIPRange(IPString) // 获取 IP 最后一段最小值和最大值
Mask, _ := strconv.Atoi(strings.Split(IPString, "/")[1]) // 获取子网掩码
MaxIPNum := getCidrHostNum(Mask) // 根据子网掩码获取主机数量
for IPRange.Contains(firstIP) {
if allip { // 如果是测速全部 IP
for i := int(minIP); i <= int(maxIP); i++ { // 遍历 IP 最后一段最小值到最大值
@@ -101,8 +108,10 @@ func loadFirstIPOfRangeFromFile(ipFile string) []net.IPAddr {
for IPRange.Contains(firstIP) {
//fmt.Println(firstIP)
//fmt.Println(firstIP[0], firstIP[1], firstIP[2], firstIP[3], firstIP[4], firstIP[5], firstIP[6], firstIP[7], firstIP[8], firstIP[9], firstIP[10], firstIP[11], firstIP[12], firstIP[13], firstIP[14], firstIP[15])
firstIP[15] = randipEndWith(255) // 随机 IP 的最后一段
firstIP[14] = randipEndWith(255) // 随机 IP 的最后一段
if !strings.Contains(IPString, "/128") {
firstIP[15] = randipEndWith(255) // 随机 IP 的最后一段
firstIP[14] = randipEndWith(255) // 随机 IP 的最后一段
}
firstIPCopy := make([]byte, len(firstIP))
copy(firstIPCopy, firstIP)
firstIPs = append(firstIPs, net.IPAddr{IP: firstIPCopy})

133
README.md
View File

@@ -1,26 +1,25 @@
# XIU2/CloudflareSpeedTest
[![Go Version](https://img.shields.io/github/go-mod/go-version/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=Go&color=00ADD8)](https://github.com/XIU2/CloudflareSpeedTest/blob/master/go.mod)
[![Release Version](https://img.shields.io/github/v/release/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=Release&color=1784ff)](https://github.com/XIU2/CloudflareSpeedTest/releases/latest)
[![GitHub license](https://img.shields.io/github/license/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=License&color=f38020)](https://github.com/XIU2/CloudflareSpeedTest/blob/master/LICENSE)
[![GitHub Star](https://img.shields.io/github/stars/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=Star&color=f38020)](https://github.com/XIU2/CloudflareSpeedTest/stargazers)
[![GitHub Fork](https://img.shields.io/github/forks/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=Fork&color=f38020)](https://github.com/XIU2/CloudflareSpeedTest/network/members)
[![Go Version](https://img.shields.io/github/go-mod/go-version/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=Go&color=00ADD8&logo=go)](https://github.com/XIU2/CloudflareSpeedTest/)
[![Release Version](https://img.shields.io/github/v/release/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=Release&color=1784ff&logo=github)](https://github.com/XIU2/CloudflareSpeedTest/releases/latest)
[![GitHub license](https://img.shields.io/github/license/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=License&color=f38020&logo=github)](https://github.com/XIU2/CloudflareSpeedTest/)
[![GitHub Star](https://img.shields.io/github/stars/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=Star&color=f38020&logo=github)](https://github.com/XIU2/CloudflareSpeedTest/)
[![GitHub Fork](https://img.shields.io/github/forks/XIU2/CloudflareSpeedTest.svg?style=flat-square&label=Fork&color=f38020&logo=github)](https://github.com/XIU2/CloudflareSpeedTest/)
[国外很多网站](https://github.com/XIU2/CloudflareSpeedTest/discussions/62)都在使用 Cloudflare CDN但分配给中国访客的 IP 并不友好(高延迟/高丢包/速度慢等)。
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,所以就有了这个软件。
该软件可以**测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**觉得好用请**点个⭐鼓励一下~**
**「自选 IP/优选 IP」测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**好用的话**点个⭐鼓励一下~**
> _本项目也**适用于其他 CDN**,但是需要自行寻找 **CDN IP 段及下载测速地址**否则只能延迟测速。_
> _我另一个开源项目 **[一个 \[油猴脚本\] 轻松解决「Github」文件下载速度慢的问题](https://github.com/XIU2/UserScript)**_
> _分享我的其他开源项目:[**TrackersList.com** - 全网热门 BT Tracker 列表!有效提高 BT 下载速度~](https://github.com/XIU2/TrackersListCollection) <img src="https://img.shields.io/github/stars/XIU2/TrackersListCollection.svg?style=flat-square&label=Star&color=4285dd&logo=github" height="16px" />_
> _[一个 **\[油猴脚本\]** 轻松解决「Github」文件下载速度慢的问题](https://github.com/XIU2/UserScript)(及十几个油猴脚本 <img src="https://img.shields.io/github/stars/XIU2/UserScript.svg?style=flat-square&label=Star&color=4285dd&logo=github" height="16px" />_
****
## 快速使用
### 下载运行
1. 下载编译好的可执行文件 [蓝奏云](https://xiu.lanzoux.com/b0742hkxe) / [Github](https://github.com/XIU2/CloudflareSpeedTest/releases) 并解压。
1. 下载编译好的可执行文件 [蓝奏云](https://pan.lanzoui.com/b0742hkxe) / [Github](https://github.com/XIU2/CloudflareSpeedTest/releases) 并解压。
2. 双击运行 `CloudflareST.exe`文件Windows等待测速完成...
<details>
@@ -38,7 +37,7 @@ mkdir CloudflareST
cd CloudflareST
# 下载 CloudflareST 压缩包(自行根据需求替换 URL 中版本号和文件名)
wget -N https://github.com/XIU2/CloudflareSpeedTest/releases/download/v1.4.7/CloudflareST_linux_amd64.tar.gz
wget -N https://github.com/XIU2/CloudflareSpeedTest/releases/download/v1.5.0/CloudflareST_linux_amd64.tar.gz
# 解压(不需要删除旧文件,会直接覆盖,自行根据需求替换 文件名)
tar -zxf CloudflareST_linux_amd64.tar.gz
@@ -80,7 +79,10 @@ IP 地址 已发送 已接收 丢包率 平均延迟 下载速度
# 如果平均延迟非常低(如 0.xx则说明 CloudflareST 测速时走了代理,请先关闭代理软件后再测速。
# 如果在路由器上运行(如 OpenWrt请先关闭路由器内的代理否则测速结果会不准确且无法使用。
# 因为默认下载测速地址的文件大小只有 300MB如果你速度太快的话测速结果可能会低于实际速度。
# 因为每次测速都是在每个 IP 段中随机 IP所以每次的测速结果都不可能相同这是正常的
# 软件是先 延迟测速并按从低到高排序后,再从 最低延迟的 IP 开始下载测速的,所以:
```
@@ -121,15 +123,17 @@ https://github.com/XIU2/CloudflareSpeedTest
-url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
下载测速地址;用来下载测速的 Cloudflare CDN 文件地址,如地址含有空格请加上引号;
-tl 200
平均延迟上限;只输出低于指定平均延迟的 IP单独使用也可搭配下载速度下限(默认 9999.00 ms)
平均延迟上限;只输出低于指定平均延迟的 IP与其他上限/下限搭配(默认 9999 ms)
-tll 40
平均延迟下限;只输出高于指定平均延迟的 IP可与其他上限/下限搭配,过滤被假蔷的 IP(默认 0 ms)
-sl 5
下载速度下限;只输出高于指定下载速度的 IP凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s )
下载速度下限;只输出高于指定下载速度的 IP凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
-p 20
显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 20 )
-f ip.txt
IP段数据文件如路径含有空格请加上引号支持其他 CDN IP段(默认 ip.txt )
-o result.csv
输出结果文件;如路径含有空格请加上引号;值为空时不输出 [-o " "](默认 result.csv )
写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""](默认 result.csv )
-dd
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序)(默认 启用 )
-ipv6
@@ -144,7 +148,7 @@ https://github.com/XIU2/CloudflareSpeedTest
### 使用示例
Windows 在 CMD 中运行,或者把相关参数添加到快捷方式目标中。
Windows 要指定参数需要在 CMD 中运行,或者把参数添加到快捷方式目标中。
> **注意**:各参数均有**默认值**,使用默认值的参数是可以省略的(**按需选择**),参数**不分前后顺序**。
> **提示**Linux 系统只需要把下面命令中的 `CloudflareST.exe` 改为 `./CloudflareST` 即可。
@@ -152,10 +156,10 @@ Windows 是在 CMD 中运行,或者把相关参数添加到快捷方式目标
#### \# IPv4/IPv6
``` bash
# 指定 IPv4 数据文件(-f 默认值就是 ip.txt所以该参数可以省略
# 测速 IPv4 时,需要指定 IPv4 数据文件(-f 默认值就是 ip.txt所以该参数可以省略
CloudflareST.exe -f ip.txt
# 指定 IPv6 数据文件( ipv6.txt ),需要加上 -ipv6 参数
# 测速 IPv6 时,需要指定 IPv6 数据文件( ipv6.txt ),需要加上 -ipv6 参数
CloudflareST.exe -f ipv6.txt -ipv6
```
****
@@ -163,16 +167,16 @@ CloudflareST.exe -f ipv6.txt -ipv6
``` bash
# 指定 IPv4 数据文件,不显示结果直接退出,输出结果到文件(-p 值为 0
CloudflareST.exe -f ip.txt -p 0 -dd
CloudflareST.exe -f 1.txt -p 0 -dd
# 指定 IPv4 数据文件,不输出结果到文件,直接显示结果(-p 值为 10 条,-o 值为空
CloudflareST.exe -f ip.txt -o " " -p 10 -dd
# 指定 IPv4 数据文件,不输出结果到文件,直接显示结果(-p 值为 10 条,-o 值为空但引号不能少
CloudflareST.exe -f 2.txt -o "" -p 10 -dd
# 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录下,如含空格请加上引号)
CloudflareST.exe -f ip.txt -o result.csv -dd
CloudflareST.exe -f 3.txt -o result.txt -dd
# 指定 IPv4 数据文件 及 输出结果到文件(绝对路径,即 C:\abc\ 目录下,如含空格请加上引号)
CloudflareST.exe -f C:\abc\ip.txt -o C:\abc\result.csv -dd
CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
```
****
#### \# 自定义下载测速地址
@@ -180,44 +184,64 @@ CloudflareST.exe -f C:\abc\ip.txt -o C:\abc\result.csv -dd
``` bash
# 地址要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN
CloudflareST.exe -url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
# 因为默认下载测速地址的文件大小只有 300MB如果你速度太快的话测速结果可能会低于实际速度。
```
****
#### \# 自定义测速条件
<details>
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
****
- 指定 **[平均延迟下限]** 条件(用于过滤**被假蔷的 IP**,这类 IP 都被 TCP 劫持因此延迟很低只有几十ms
``` bash
# 平均延迟下限40 ms (一般除了移动直连香港外,几乎不存在低于 100ms 的,自行测试适合的下限延迟)
# 平均延迟下限和其他的上下限参数一样,都可以单独使用、互相搭配使用!
CloudflareST.exe -tll 40
```
- 仅指定 **[平均延迟上限]** 条件
``` bash
# 平均延迟上限200 ms下载速度下限0 MB/s数量10 个
# 平均延迟上限200 ms下载速度下限0 MB/s数量10 个(可选)
# 即找到平均延迟低于 200 ms 的 IP然后再按延迟从低到高进行 10 次下载测速
CloudflareST.exe -tl 200 -dn 10
```
> 如果没有一个 IP **平均延迟低于 200ms**,那么不会输出任何内容。
****
- 仅指定 **[平均延迟上限]** 条件,且**只延迟测速,不下载测速**
``` bash
# 平均延迟上限200 ms下载速度下限0 MB/s数量无限
# 平均延迟上限200 ms下载速度下限0 MB/s数量不知道多少
# 即只输出低于 200ms 的 IP且不再下载测速因为不再下载测速所以 -dn 参数就无效了)
CloudflareST.exe -tl 200 -dd
```
****
- 仅指定 **[下载速度下限]** 条件
``` bash
# 平均延迟上限9999 ms下载速度下限5 MB/s数量10 个( 可选)
# 平均延迟上限9999 ms下载速度下限5 MB/s数量10 个(可选)
# 即需要找到 10 个平均延迟低于 9999 ms 且下载速度高于 5 MB/s 的 IP 才会停止测速
CloudflareST.exe -sl 5 -dn 10
```
> 没有指定平均延迟上限时,如果一直**凑不够**满足条件的 IP 数量,就会**一直测速**下去。
> 所以建议**同时指定 下载速度下限平均延迟上限**,这样测速到指定延迟上限还没凑够数量,就会终止测速。
> 所以建议**同时指定 [下载速度下限] + [平均延迟上限]**,这样测速到指定延迟上限还没凑够数量,就会终止测速。
****
- 同时指定 **[平均延迟上限] + [下载速度下限]** 条件
``` bash
# 平均延迟上限、下载速度下限均支持小数(如 -sl 0.5
# 平均延迟上限200 ms下载速度下限5.6 MB/s数量10 个( 可选)
# 平均延迟上限200 ms下载速度下限5.6 MB/s数量10 个(可选)
# 即需要找到 10 个平均延迟低于 200 ms 且下载速度高于 5 .6MB/s 的 IP 才会停止测速
CloudflareST.exe -tl 200 -sl 5.6 -dn 10
```
@@ -226,11 +250,18 @@ CloudflareST.exe -tl 200 -sl 5.6 -dn 10
> 如果没有一个 IP **下载速度高于 5.6 MB/s**,那么就会**和不指定 [下载速度下限] 条件一样**输出结果。
> 所以建议先不指定条件测速一遍,看看平均延迟和下载速度大概在什么范围,避免指定条件**过低/过高**
> 因为 Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法用来指向网站的,所以下载测速是 0.00。
> 运行时可以加上 `-sl 0.01`(下载速度下限,最小值 0.01),过滤掉**回源 IP**(下载测速于 0.01MB/s 的结果)。
> 因为Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法使用的,所以下载测速是 0.00。
> 运行时可以加上 `-sl 0.01`(下载速度下限),过滤掉**回源 IP**(下载测速于 0.01MB/s 的结果)。
</details>
****
#### \# Windows 快捷方式如何使用参数
<details>
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
****
#### \# Windows 快捷方式
``` bash
## 右键快捷方式 - 目标
@@ -240,32 +271,53 @@ D:\ABC\CloudflareST\CloudflareST.exe -n 500 -t 4 -dn 20 -dt 5 -o " "
# 如果文件路径包含引号,则需要把启动参数放在引号外面,记得引号和 - 之间有空格。
"D:\Program Files\CloudflareST\CloudflareST.exe" -n 500 -t 4 -dn 20 -dt 5 -o " "
```
</details>
****
#### \# 单独对一个或多个 IP 测速
<details>
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
****
#### \# 单独测速 IP
如果要单独**对一个或多个 IP 进行测速**,只需要把这些 IP 按如下格式写入到任意文本文件中,例如:`1.txt`
``` json
1.1.1.1/32
1.1.1.1
1.1.1.200
1.0.0.1/24
// 子网掩码 /32 指的是这个 IP 本身,即 1.1.1.1
// 子网掩码 /24 指的是这个 IP 最后一段,即 1.0.0.1~1.0.0.255
```
> 自从 v1.4.10 版本后,单个 IP 就不需要添加子网掩码 `/32` 了(`1.1.1.1`等同于 `1.1.1.1/32`)。
> 子网掩码 `/24` 指的是这个 IP 最后一段,即 `1.0.0.1~1.0.0.255`。
然后运行 CloudflareST 时加上启动参数 `-f 1.txt` 即可。
``` bash
# 先进入 CloudflareST 所在目录,然后运行:
# Windows在 CMD 中运行)
# Windows 系统(在 CMD 中运行)
CloudflareST.exe -f 1.txt
# Linux
# Linux 系统
./CloudflareST -f 1.txt
# 对于 IP 段 1.0.0.1/24 软件只会随机最后一段1.0.0.1~255如果要测速该 IP 段中的所有 IP需要加上 -allip 参数。
```
</details>
****
#### \# 一劳永逸加速所有使用 Cloudflare CDN 的网站(不需要再一个个添加域名到 Hosts 了)
我以前说过,开发该软件项目的目的就是为了通过**改 Hosts 的方式来加速访问使用 Cloudflare CDN 的网站**。
但就如 [**#8**](https://github.com/XIU2/CloudflareSpeedTest/issues/8) 所说,一个个添加域名到 Hosts 实在**太麻烦**了,于是我就找到了个**一劳永逸**的办法!
可以看这个 [**还在一个个添加 Hosts完美本地加速所有使用 Cloudflare CDN 的网站方法来了!**](https://github.com/XIU2/CloudflareSpeedTest/discussions/71)
****
#### \# 自动更新 Hosts
@@ -273,13 +325,6 @@ CloudflareST.exe -f 1.txt
可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/42) 获取 **Windows/Linux 自动更新 Hosts 脚本**
****
#### \# 自动更新域名解析记录
如果你的域名托管在 Cloudflare则可以通过 Cloudflare 官方提供的 API 来自动更新域名解析记录。
可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/40) 获取**手动教程**或 **Windows/Linux 自动更新脚本**
****
## 问题反馈

27
ip.txt
View File

@@ -2,17 +2,22 @@
1.0.0.0/24
1.1.1.1/32
1.0.0.1/32
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
173.245.49.0/24
103.21.244.0/24
141.101.64.0/18
108.162.192.0/18
190.93.240.0/20
188.114.96.0/20
197.234.240.0/22
198.41.128.0/17
162.158.0.0/15
104.16.0.0/12
172.64.0.0/13
131.0.72.0/22
162.159.0.0/16
104.16.0.0/13
104.24.0.0/14
172.64.0.0/17
172.64.128.0/18
172.64.192.0/19
172.64.224.0/22
172.64.229.0/24
172.64.230.0/23
172.64.232.0/21
172.64.240.0/21
172.64.248.0/21
172.65.0.0/16
172.67.0.0/16

19
ipall.txt Normal file
View File

@@ -0,0 +1,19 @@
1.1.1.0/24
1.0.0.0/24
1.1.1.1/32
1.0.0.1/32
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
104.16.0.0/13
104.24.0.0/14
108.162.192.0/18
131.0.72.0/22
141.101.64.0/18
162.158.0.0/15
172.64.0.0/13
173.245.48.0/20
188.114.96.0/20
190.93.240.0/20
197.234.240.0/22
198.41.128.0/17

40
main.go
View File

@@ -18,7 +18,7 @@ import (
var version, ipFile, outputFile, versionNew string
var disableDownload, ipv6Mode, allip bool
var tcpPort, printResultNum, downloadSecond int
var timeLimit, speedLimit float64
var timeLimit, timeLimitLow, speedLimit float64
func init() {
var printVersion bool
@@ -28,8 +28,8 @@ CloudflareSpeedTest ` + version + `
https://github.com/XIU2/CloudflareSpeedTest
参数:
-n 500
测速线程数量;越多测速越快,性能弱的设备 (如路由器) 请适当调低(默认 500 最多 1000)
-n 200
测速线程数量;越多测速越快,性能弱的设备 (如路由器) 请勿太高(默认 200 最多 1000)
-t 4
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IPTCP协议(默认 4)
-tp 443
@@ -41,7 +41,9 @@ https://github.com/XIU2/CloudflareSpeedTest
-url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
下载测速地址;用来下载测速的 Cloudflare CDN 文件地址,如地址含有空格请加上引号;
-tl 200
平均延迟上限;只输出低于指定平均延迟的 IP单独使用也可搭配下载速度下限(默认 9999.00 ms)
平均延迟上限;只输出低于指定平均延迟的 IP与其他上限/下限搭配(默认 9999 ms)
-tll 40
平均延迟下限;只输出高于指定平均延迟的 IP可与其他上限/下限搭配,过滤被假蔷的 IP(默认 0 ms)
-sl 5
下载速度下限;只输出高于指定下载速度的 IP凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
-p 20
@@ -49,7 +51,7 @@ https://github.com/XIU2/CloudflareSpeedTest
-f ip.txt
IP段数据文件如路径含有空格请加上引号支持其他 CDN IP段(默认 ip.txt)
-o result.csv
输出结果文件;如路径含有空格请加上引号;值为空时不输出 [-o " "](默认 result.csv)
写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""](默认 result.csv)
-dd
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序)(默认 启用)
-ipv6
@@ -62,13 +64,14 @@ https://github.com/XIU2/CloudflareSpeedTest
打印帮助说明
`
flag.IntVar(&pingRoutine, "n", 500, "测速线程数量")
flag.IntVar(&pingRoutine, "n", 200, "测速线程数量")
flag.IntVar(&pingTime, "t", 4, "延迟测速次数")
flag.IntVar(&tcpPort, "tp", 443, "延迟测速端口")
flag.IntVar(&downloadTestCount, "dn", 20, "下载测速数量")
flag.IntVar(&downloadSecond, "dt", 10, "下载测速时间")
flag.StringVar(&url, "url", "https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png", "下载测速地址")
flag.Float64Var(&timeLimit, "tl", 9999, "平均延迟上限")
flag.Float64Var(&timeLimitLow, "tll", 0, "平均延迟下限")
flag.Float64Var(&speedLimit, "sl", 0, "下载速度下限")
flag.IntVar(&printResultNum, "p", 20, "显示结果数量")
flag.BoolVar(&disableDownload, "dd", false, "禁用下载测速")
@@ -92,7 +95,7 @@ https://github.com/XIU2/CloudflareSpeedTest
os.Exit(0)
}
if pingRoutine <= 0 {
pingRoutine = 500
pingRoutine = 200
}
if pingTime <= 0 {
pingTime = 4
@@ -109,9 +112,12 @@ https://github.com/XIU2/CloudflareSpeedTest
if url == "" {
url = "https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png"
}
if timeLimit <= 0 {
if timeLimit <= 0 || timeLimit > 9999 {
timeLimit = 9999
}
if timeLimitLow < 0 || timeLimitLow > 9999 {
timeLimitLow = 0
}
if speedLimit < 0 {
speedLimit = 0
}
@@ -142,9 +148,9 @@ func main() {
// 开始延迟测速
fmt.Println("# XIU2/CloudflareSpeedTest " + version + "\n")
if ipv6Mode { // IPv6 模式判断
fmt.Println("开始延迟测速模式TCP IPv6端口" + strconv.Itoa(tcpPort) + ",平均延迟上限:" + fmt.Sprintf("%.2f", timeLimit) + " ms")
fmt.Println("开始延迟测速模式TCP IPv6端口" + strconv.Itoa(tcpPort) + ",平均延迟上限:" + fmt.Sprintf("%.2f", timeLimit) + " ms" + ",平均延迟下限:" + fmt.Sprintf("%.2f", timeLimitLow) + " ms")
} else {
fmt.Println("开始延迟测速模式TCP IPv4端口" + strconv.Itoa(tcpPort) + ",平均延迟上限:" + fmt.Sprintf("%.2f", timeLimit) + " ms")
fmt.Println("开始延迟测速模式TCP IPv4端口" + strconv.Itoa(tcpPort) + ",平均延迟上限:" + fmt.Sprintf("%.2f", timeLimit) + " ms" + ",平均延迟下限:" + fmt.Sprintf("%.2f", timeLimitLow) + " ms")
}
control := make(chan bool, pingRoutine)
for _, ip := range ips {
@@ -158,11 +164,15 @@ func main() {
sort.Sort(CloudflareIPDataSet(data)) // 排序(按延迟,从低到高,不同丢包率会分开单独按延迟和丢包率排序)
// 延迟测速完毕后,以 [平均延迟上限] 条件过滤结果
if timeLimit < 9999 && timeLimit > 0 {
// 延迟测速完毕后,以 [平均延迟上限] + [平均延迟下限] 条件过滤结果
if timeLimit != 9999 || timeLimitLow != 0 {
for i := 0; i < len(data); i++ {
if float64(data[i].pingTime) <= timeLimit {
data2 = append(data2, data[i]) // 延迟满足条件时,添加到新数组中
if float64(data[i].pingTime) <= timeLimit { // 平均延迟上限
if float64(data[i].pingTime) > timeLimitLow { // 平均延迟下限
data2 = append(data2, data[i]) // 延迟满足条件时,添加到新数组中
} else {
continue
}
} else {
break
}
@@ -235,7 +245,7 @@ func printResult(data []CloudflareIPData) {
}
if versionNew != "" {
fmt.Println("\n发现新版本 [" + versionNew + "]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新!")
fmt.Println("\n*** 发现新版本 [" + versionNew + "]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***")
}
if sysType == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)