21 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
5 changed files with 124 additions and 57 deletions

View File

@@ -64,8 +64,12 @@ func loadFirstIPOfRangeFromFile(ipFile string) []net.IPAddr {
scanner.Split(bufio.ScanLines) scanner.Split(bufio.ScanLines)
for scanner.Scan() { for scanner.Scan() {
IPString := scanner.Text() IPString := scanner.Text()
if !strings.Contains(IPString, "/") { // 如果不含有 / 则代表不是 IP 段,而是一个单独的 IP因此需要加上 /32 子网掩码 if !strings.Contains(IPString, "/") { // 如果不含有 / 则代表不是 IP 段,而是一个单独的 IP因此需要加上 /32 /128 子网掩码
IPString += "/32" if ipv6Mode {
IPString += "/128"
} else {
IPString += "/32"
}
} }
firstIP, IPRange, err := net.ParseCIDR(IPString) firstIP, IPRange, err := net.ParseCIDR(IPString)
//fmt.Println(firstIP) //fmt.Println(firstIP)
@@ -104,8 +108,10 @@ func loadFirstIPOfRangeFromFile(ipFile string) []net.IPAddr {
for IPRange.Contains(firstIP) { for IPRange.Contains(firstIP) {
//fmt.Println(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]) //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 的最后一段 if !strings.Contains(IPString, "/128") {
firstIP[14] = randipEndWith(255) // 随机 IP 的最后一段 firstIP[15] = randipEndWith(255) // 随机 IP 的最后一段
firstIP[14] = randipEndWith(255) // 随机 IP 的最后一段
}
firstIPCopy := make([]byte, len(firstIP)) firstIPCopy := make([]byte, len(firstIP))
copy(firstIPCopy, firstIP) copy(firstIPCopy, firstIP)
firstIPs = append(firstIPs, net.IPAddr{IP: firstIPCopy}) firstIPs = append(firstIPs, net.IPAddr{IP: firstIPCopy})

105
README.md
View File

@@ -1,24 +1,25 @@
# XIU2/CloudflareSpeedTest # 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) [![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)](https://github.com/XIU2/CloudflareSpeedTest/releases/latest) [![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)](https://github.com/XIU2/CloudflareSpeedTest/blob/master/LICENSE) [![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)](https://github.com/XIU2/CloudflareSpeedTest/stargazers) [![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)](https://github.com/XIU2/CloudflareSpeedTest/network/members) [![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 并不友好(高延迟/高丢包/速度慢等)。 [国外很多网站](https://github.com/XIU2/CloudflareSpeedTest/discussions/62)都在使用 Cloudflare CDN但分配给中国访客的 IP 并不友好(高延迟/高丢包/速度慢等)。
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,所以就有了这个软件。 虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,所以就有了这个软件。
该软件可以**测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**觉得好用请**点个⭐鼓励一下~** **「自选 IP/优选 IP」测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**好用的话**点个⭐鼓励一下~**
> _我另一个开源项目: **[一个 \[油猴脚本\] 轻松解决「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等待测速完成... 2. 双击运行 `CloudflareST.exe`文件Windows等待测速完成...
<details> <details>
@@ -36,7 +37,7 @@ mkdir CloudflareST
cd CloudflareST cd CloudflareST
# 下载 CloudflareST 压缩包(自行根据需求替换 URL 中版本号和文件名) # 下载 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 tar -zxf CloudflareST_linux_amd64.tar.gz
@@ -78,7 +79,10 @@ IP 地址 已发送 已接收 丢包率 平均延迟 下载速度
# 如果平均延迟非常低(如 0.xx则说明 CloudflareST 测速时走了代理,请先关闭代理软件后再测速。 # 如果平均延迟非常低(如 0.xx则说明 CloudflareST 测速时走了代理,请先关闭代理软件后再测速。
# 如果在路由器上运行(如 OpenWrt请先关闭路由器内的代理否则测速结果会不准确且无法使用。 # 如果在路由器上运行(如 OpenWrt请先关闭路由器内的代理否则测速结果会不准确且无法使用。
# 因为默认下载测速地址的文件大小只有 300MB如果你速度太快的话测速结果可能会低于实际速度。
# 因为每次测速都是在每个 IP 段中随机 IP所以每次的测速结果都不可能相同这是正常的 # 因为每次测速都是在每个 IP 段中随机 IP所以每次的测速结果都不可能相同这是正常的
# 软件是先 延迟测速并按从低到高排序后,再从 最低延迟的 IP 开始下载测速的,所以: # 软件是先 延迟测速并按从低到高排序后,再从 最低延迟的 IP 开始下载测速的,所以:
``` ```
@@ -119,15 +123,17 @@ https://github.com/XIU2/CloudflareSpeedTest
-url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png -url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
下载测速地址;用来下载测速的 Cloudflare CDN 文件地址,如地址含有空格请加上引号; 下载测速地址;用来下载测速的 Cloudflare CDN 文件地址,如地址含有空格请加上引号;
-tl 200 -tl 200
平均延迟上限;只输出低于指定平均延迟的 IP单独使用也可搭配下载速度下限(默认 9999.00 ms) 平均延迟上限;只输出低于指定平均延迟的 IP与其他上限/下限搭配(默认 9999 ms)
-tll 40
平均延迟下限;只输出高于指定平均延迟的 IP可与其他上限/下限搭配,过滤被假蔷的 IP(默认 0 ms)
-sl 5 -sl 5
下载速度下限;只输出高于指定下载速度的 IP凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s ) 下载速度下限;只输出高于指定下载速度的 IP凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
-p 20 -p 20
显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 20 ) 显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 20 )
-f ip.txt -f ip.txt
IP段数据文件如路径含有空格请加上引号支持其他 CDN IP段(默认 ip.txt ) IP段数据文件如路径含有空格请加上引号支持其他 CDN IP段(默认 ip.txt )
-o result.csv -o result.csv
输出结果文件;如路径含有空格请加上引号;值为空时不输出 [-o " "](默认 result.csv ) 写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""](默认 result.csv )
-dd -dd
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序)(默认 启用 ) 禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序)(默认 启用 )
-ipv6 -ipv6
@@ -142,7 +148,7 @@ https://github.com/XIU2/CloudflareSpeedTest
### 使用示例 ### 使用示例
Windows 在 CMD 中运行,或者把相关参数添加到快捷方式目标中。 Windows 要指定参数需要在 CMD 中运行,或者把参数添加到快捷方式目标中。
> **注意**:各参数均有**默认值**,使用默认值的参数是可以省略的(**按需选择**),参数**不分前后顺序**。 > **注意**:各参数均有**默认值**,使用默认值的参数是可以省略的(**按需选择**),参数**不分前后顺序**。
> **提示**Linux 系统只需要把下面命令中的 `CloudflareST.exe` 改为 `./CloudflareST` 即可。 > **提示**Linux 系统只需要把下面命令中的 `CloudflareST.exe` 改为 `./CloudflareST` 即可。
@@ -150,10 +156,10 @@ Windows 是在 CMD 中运行,或者把相关参数添加到快捷方式目标
#### \# IPv4/IPv6 #### \# IPv4/IPv6
``` bash ``` bash
# 指定 IPv4 数据文件(-f 默认值就是 ip.txt所以该参数可以省略 # 测速 IPv4 时,需要指定 IPv4 数据文件(-f 默认值就是 ip.txt所以该参数可以省略
CloudflareST.exe -f ip.txt CloudflareST.exe -f ip.txt
# 指定 IPv6 数据文件( ipv6.txt ),需要加上 -ipv6 参数 # 测速 IPv6 时,需要指定 IPv6 数据文件( ipv6.txt ),需要加上 -ipv6 参数
CloudflareST.exe -f ipv6.txt -ipv6 CloudflareST.exe -f ipv6.txt -ipv6
``` ```
**** ****
@@ -161,16 +167,16 @@ CloudflareST.exe -f ipv6.txt -ipv6
``` bash ``` bash
# 指定 IPv4 数据文件,不显示结果直接退出,输出结果到文件(-p 值为 0 # 指定 IPv4 数据文件,不显示结果直接退出,输出结果到文件(-p 值为 0
CloudflareST.exe -f ip.txt -p 0 -dd CloudflareST.exe -f 1.txt -p 0 -dd
# 指定 IPv4 数据文件,不输出结果到文件,直接显示结果(-p 值为 10 条,-o 值为空 # 指定 IPv4 数据文件,不输出结果到文件,直接显示结果(-p 值为 10 条,-o 值为空但引号不能少
CloudflareST.exe -f ip.txt -o " " -p 10 -dd CloudflareST.exe -f 2.txt -o "" -p 10 -dd
# 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录下,如含空格请加上引号) # 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录下,如含空格请加上引号)
CloudflareST.exe -f ip.txt -o result.csv -dd CloudflareST.exe -f 3.txt -o result.txt -dd
# 指定 IPv4 数据文件 及 输出结果到文件(绝对路径,即 C:\abc\ 目录下,如含空格请加上引号) # 指定 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
``` ```
**** ****
#### \# 自定义下载测速地址 #### \# 自定义下载测速地址
@@ -178,11 +184,25 @@ CloudflareST.exe -f C:\abc\ip.txt -o C:\abc\result.csv -dd
``` bash ``` bash
# 地址要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN # 地址要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN
CloudflareST.exe -url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png 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 ``` bash
# 平均延迟上限200 ms下载速度下限0 MB/s数量10 个(可选) # 平均延迟上限200 ms下载速度下限0 MB/s数量10 个(可选)
@@ -194,7 +214,7 @@ CloudflareST.exe -tl 200 -dn 10
**** ****
- \# 仅指定 **[平均延迟上限]** 条件,且**只延迟测速,不下载测速** - 仅指定 **[平均延迟上限]** 条件,且**只延迟测速,不下载测速**
``` bash ``` bash
# 平均延迟上限200 ms下载速度下限0 MB/s数量不知道多少 个 # 平均延迟上限200 ms下载速度下限0 MB/s数量不知道多少 个
@@ -204,7 +224,7 @@ CloudflareST.exe -tl 200 -dd
**** ****
- \# 仅指定 **[下载速度下限]** 条件 - 仅指定 **[下载速度下限]** 条件
``` bash ``` bash
# 平均延迟上限9999 ms下载速度下限5 MB/s数量10 个(可选) # 平均延迟上限9999 ms下载速度下限5 MB/s数量10 个(可选)
@@ -217,7 +237,7 @@ CloudflareST.exe -sl 5 -dn 10
**** ****
- \# 同时指定 **[平均延迟上限] + [下载速度下限]** 条件 - 同时指定 **[平均延迟上限] + [下载速度下限]** 条件
``` bash ``` bash
# 平均延迟上限、下载速度下限均支持小数(如 -sl 0.5 # 平均延迟上限、下载速度下限均支持小数(如 -sl 0.5
@@ -233,8 +253,15 @@ CloudflareST.exe -tl 200 -sl 5.6 -dn 10
> 因为Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法使用的,所以下载测速是 0.00。 > 因为Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法使用的,所以下载测速是 0.00。
> 运行时可以加上 `-sl 0.01`(下载速度下限),过滤掉**回源 IP**(下载测速低于 0.01MB/s 的结果)。 > 运行时可以加上 `-sl 0.01`(下载速度下限),过滤掉**回源 IP**(下载测速低于 0.01MB/s 的结果)。
</details>
****
#### \# Windows 快捷方式如何使用参数
<details>
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
**** ****
#### \# Windows 快捷方式
``` bash ``` bash
## 右键快捷方式 - 目标 ## 右键快捷方式 - 目标
@@ -244,17 +271,26 @@ 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 " " "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` 如果要单独**对一个或多个 IP 进行测速**,只需要把这些 IP 按如下格式写入到任意文本文件中,例如:`1.txt`
``` json ``` json
1.1.1.1/32 1.1.1.1
1.1.1.200
1.0.0.1/24 1.0.0.1/24
``` ```
> 子网掩码 `/32` 指的是这个 IP 本身,即 `1.1.1.1`。 > 自从 v1.4.10 版本后,单个 IP 就不需要添加子网掩码 `/32` 了(`1.1.1.1`等同于 `1.1.1.1/32`
> 子网掩码 `/24` 指的是这个 IP 最后一段,即 `1.0.0.1~1.0.0.255`。 > 子网掩码 `/24` 指的是这个 IP 最后一段,即 `1.0.0.1~1.0.0.255`。
@@ -271,14 +307,16 @@ CloudflareST.exe -f 1.txt
# 对于 IP 段 1.0.0.1/24 软件只会随机最后一段1.0.0.1~255如果要测速该 IP 段中的所有 IP需要加上 -allip 参数。 # 对于 IP 段 1.0.0.1/24 软件只会随机最后一段1.0.0.1~255如果要测速该 IP 段中的所有 IP需要加上 -allip 参数。
``` ```
</details>
**** ****
#### \# 一劳永逸加速所有使用 Cloudflare CDN 的网站(不需要再一个个添加域名到 Hosts 了) #### \# 一劳永逸加速所有使用 Cloudflare CDN 的网站(不需要再一个个添加域名到 Hosts 了)
我以前说过,开发该软件项目的目的就是为了通过**改 Hosts 的方式来加速访问使用 Cloudflare CDN 的网站**。 我以前说过,开发该软件项目的目的就是为了通过**改 Hosts 的方式来加速访问使用 Cloudflare CDN 的网站**。
但就如 #8 所说,一个个添加域名到 Hosts 实在**太麻烦**了,于是我就找到了个**一劳永逸**的办法! 但就如 [**#8**](https://github.com/XIU2/CloudflareSpeedTest/issues/8) 所说,一个个添加域名到 Hosts 实在**太麻烦**了,于是我就找到了个**一劳永逸**的办法!
可以看这个 [**还在一个个添加 Hosts完美本地加速所有使用 Cloudflare CDN 的网站方法来了!**](https://github.com/XIU2/CloudflareSpeedTest/discussions/71) 可以看这个 [**还在一个个添加 Hosts完美本地加速所有使用 Cloudflare CDN 的网站方法来了!**](https://github.com/XIU2/CloudflareSpeedTest/discussions/71)
**** ****
#### \# 自动更新 Hosts #### \# 自动更新 Hosts
@@ -287,13 +325,6 @@ CloudflareST.exe -f 1.txt
可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/42) 获取 **Windows/Linux 自动更新 Hosts 脚本** 可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/42) 获取 **Windows/Linux 自动更新 Hosts 脚本**
****
#### \# 自动更新域名解析记录
如果你的域名托管在 Cloudflare则可以通过 Cloudflare 官方提供的 API 来自动更新域名解析记录。
可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/40) 获取**手动教程**或 **Windows/Linux 自动更新脚本**
**** ****
## 问题反馈 ## 问题反馈

3
ip.txt
View File

@@ -8,7 +8,8 @@
190.93.240.0/20 190.93.240.0/20
198.41.128.0/17 198.41.128.0/17
162.159.0.0/16 162.159.0.0/16
104.16.0.0/12 104.16.0.0/13
104.24.0.0/14
172.64.0.0/17 172.64.0.0/17
172.64.128.0/18 172.64.128.0/18
172.64.192.0/19 172.64.192.0/19

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