mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-03-07 15:15:52 +08:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f9d28e4a0 | ||
|
|
4222b6ce95 | ||
|
|
7c36abc12f | ||
|
|
eae7d2eead | ||
|
|
b6f3ddcd4c | ||
|
|
c6d49bc7cb | ||
|
|
a07af2f58b | ||
|
|
9f000aa23a | ||
|
|
1800c2e89e | ||
|
|
39d1687875 | ||
|
|
24a162ac46 | ||
|
|
3125b49b63 | ||
|
|
729631deef | ||
|
|
fe0721f077 | ||
|
|
201619ecf7 | ||
|
|
12effc301f | ||
|
|
fede8a04e6 | ||
|
|
b63f368837 | ||
|
|
c9a8c2b8cf | ||
|
|
e80d7fff50 | ||
|
|
f61a94886b | ||
|
|
f3f2bafbe7 | ||
|
|
5cf3b4bb42 | ||
|
|
6667e82c84 | ||
|
|
af4e8cf8b2 | ||
|
|
f2ec0a447c | ||
|
|
45b604103e | ||
|
|
05ba005960 | ||
|
|
a0b194f1d0 | ||
|
|
7e21b2f46b | ||
|
|
efafc38db8 | ||
|
|
b14b3657b7 | ||
|
|
2634fe43ff | ||
|
|
b26fa89447 | ||
|
|
a6b08bb4b8 | ||
|
|
bd6fbb9f1f | ||
|
|
465a83462b |
33
.github/ISSUE_TEMPLATE/01-bugReport.yml
vendored
Normal file
33
.github/ISSUE_TEMPLATE/01-bugReport.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: 反馈问题 (Bug report)
|
||||
description: 软件报错等异常情况,或遇到预期之外的问题...
|
||||
labels: 反馈问题
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
发之前,请先搜下有没有类似的 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues)、[**Discussions**](https://github.com/XIU2/CloudflareSpeedTest/discussions) 问题(包括[**已关闭**](https://github.com/XIU2/CloudflareSpeedTest/issues?q=is%3Aissue+is%3Aclosed)的),请勿重复发起!
|
||||
|
||||
注意!如果你反馈的问题和 CloudflareST **软件本身功能无关**(如关于 Cloudflare CDN 的网络问题),请**前往讨论区** (💬 [**Discussions**](https://github.com/XIU2/CloudflareSpeedTest/discussions)) 发帖交流!(不合适的 Issues 会被转过去
|
||||
****
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: 问题描述
|
||||
description: 必填,最好写上 复现问题 的步骤,越详细越好,特别是一些复杂的问题
|
||||
placeholder: 请输入...
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: 软件版本
|
||||
description: 必填,可通过运行软件来获取版本信息(例如 v2.2.2)
|
||||
placeholder: 请输入...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: 附加截图
|
||||
description: 可选,也可以是一些错误代码
|
||||
placeholder: 可在此粘贴图片,或点击下方 [Attach files by dragging & dropping, selecting or pasting them.] 文字来选择图片...
|
||||
29
.github/ISSUE_TEMPLATE/02-featureRequest.yml
vendored
Normal file
29
.github/ISSUE_TEMPLATE/02-featureRequest.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: 功能建议 (Feature request)
|
||||
description: 有什么建议,或希望添加、完善某个功能...
|
||||
labels: 功能建议
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
发之前,请先搜下有没有类似的 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues)、[**Discussions**](https://github.com/XIU2/CloudflareSpeedTest/discussions) 问题(包括[**已关闭**](https://github.com/XIU2/CloudflareSpeedTest/issues?q=is%3Aissue+is%3Aclosed)的),请勿重复发起!
|
||||
|
||||
注意!如果你提的功能建议和 CloudflareST **软件本身功能无关**,请**前往讨论区** (💬 [**Discussions**](https://github.com/XIU2/CloudflareSpeedTest/discussions)) 发帖交流!
|
||||
|
||||
> 另外,不接受**个性化**的功能请求(即 **很少人** 或 **只有你自己** 才会用到的功能)
|
||||
****
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: 功能需求
|
||||
description: 必填,你要什么样的功能?
|
||||
placeholder: 请输入...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: anticipation
|
||||
attributes:
|
||||
label: 预期目标
|
||||
description: 必填,你希望该功能具体是什么样子的?如果能提供 示例/截图/代码 就更好了
|
||||
placeholder: 请输入...
|
||||
validations:
|
||||
required: true
|
||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
5
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: 前往讨论区 (💬 Discussions)
|
||||
url: https://github.com/XIU2/CloudflareSpeedTest/discussions
|
||||
about: Issues 仅用于反馈问题、功能建议,其他话题请到 💬 Discussions 发帖讨论(不合适的 Issues 会被转过去
|
||||
184
README.md
184
README.md
@@ -7,23 +7,23 @@
|
||||
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
||||
|
||||
国外很多网站都在使用 Cloudflare CDN,但分配给中国内地访客的 IP 并不友好(延迟高、丢包多、速度慢)。
|
||||
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,于是就有了这个软件。
|
||||
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/zh-cn/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,于是就有了这个软件。
|
||||
|
||||
**「自选优选 IP」测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**!好用的话**点个`⭐`鼓励一下叭~**
|
||||
|
||||
> _分享我其他开源项目:[**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" />_
|
||||
> _[**UserScript** - 🐵 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" />_
|
||||
|
||||
> 本项目也支持对**其他 CDN / 网站 IP** 延迟测速(如:[CloudFront](https://github.com/XIU2/CloudflareSpeedTest/issues/180)、[Gcore](https://github.com/XIU2/CloudflareSpeedTest/issues/267) CDN),但下载测速需自行寻找地址
|
||||
> 本项目也支持对**其他 CDN / 网站 IP** 延迟测速(如:[CloudFront](https://github.com/XIU2/CloudflareSpeedTest/discussions/304)、[Gcore](https://github.com/XIU2/CloudflareSpeedTest/discussions/303) CDN),但下载测速需自行寻找地址
|
||||
|
||||
> 对于**代理套 Cloudflare CDN** 的用户,须知这应为**备用方案**,而不应该是**唯一方案**,请勿过度依赖 [#217](https://github.com/XIU2/CloudflareSpeedTest/issues/217) [#188](https://github.com/XIU2/CloudflareSpeedTest/issues/188)
|
||||
> 对于**代理套 Cloudflare CDN** 的用户,须知这应为**备用方案**,而不应该是**唯一方案**,请勿过度依赖 [#382](https://github.com/XIU2/CloudflareSpeedTest/discussions/382) [#383](https://github.com/XIU2/CloudflareSpeedTest/discussions/383)
|
||||
|
||||
****
|
||||
## \# 快速使用
|
||||
|
||||
### 下载运行
|
||||
|
||||
1. 下载编译好的可执行文件 [蓝奏云](https://pan.lanzouv.com/b0742hkxe) / [Github](https://github.com/XIU2/CloudflareSpeedTest/releases) 并解压。
|
||||
1. 下载编译好的可执行文件( [Github Releases](https://github.com/XIU2/CloudflareSpeedTest/releases) / [蓝奏云](https://pan.lanzouf.com/b0742hkxe) )并解压。
|
||||
2. 双击运行 `CloudflareST.exe` 文件(Windows 系统),等待测速完成...
|
||||
|
||||
<details>
|
||||
@@ -41,10 +41,10 @@ mkdir CloudflareST
|
||||
cd CloudflareST
|
||||
|
||||
# 下载 CloudflareST 压缩包(自行根据需求替换 URL 中 [版本号] 和 [文件名])
|
||||
wget -N https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.2.1/CloudflareST_linux_amd64.tar.gz
|
||||
wget -N https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.2.4/CloudflareST_linux_amd64.tar.gz
|
||||
# 如果你是在国内服务器上下载,那么请使用下面这几个镜像加速:
|
||||
# wget -N https://download.fastgit.org/XIU2/CloudflareSpeedTest/releases/download/v2.2.1/CloudflareST_linux_amd64.tar.gz
|
||||
# wget -N https://ghproxy.com/https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.2.1/CloudflareST_linux_amd64.tar.gz
|
||||
# wget -N https://download.fastgit.org/XIU2/CloudflareSpeedTest/releases/download/v2.2.4/CloudflareST_linux_amd64.tar.gz
|
||||
# wget -N https://ghproxy.com/https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.2.4/CloudflareST_linux_amd64.tar.gz
|
||||
# 如果下载失败的话,尝试删除 -N 参数(如果是为了更新,则记得提前删除旧压缩包 rm CloudflareST_linux_amd64.tar.gz )
|
||||
|
||||
# 解压(不需要删除旧文件,会直接覆盖,自行根据需求替换 文件名)
|
||||
@@ -67,7 +67,7 @@ chmod +x CloudflareST
|
||||
|
||||
****
|
||||
|
||||
> _在**手机**上独立运行 CloudflareST 测速的简单教程:**[Android](https://github.com/XIU2/CloudflareSpeedTest/discussions/61)、[Android APP](https://github.com/xianshenglu/cloudflare-ip-tester-app)、[IOS](https://github.com/XIU2/CloudflareSpeedTest/issues/151)**_
|
||||
> _在**手机**上独立运行 CloudflareST 测速的简单教程:**[Android](https://github.com/XIU2/CloudflareSpeedTest/discussions/61)、[Android APP](https://github.com/xianshenglu/cloudflare-ip-tester-app)、[IOS](https://github.com/XIU2/CloudflareSpeedTest/discussions/321)**_
|
||||
|
||||
### 结果示例
|
||||
|
||||
@@ -100,16 +100,16 @@ IP 地址 已发送 已接收 丢包率 平均延迟 下载速度
|
||||
# 2. 延迟排序(延迟从低到高排序,不同丢包率的会分开独立排序,因此可能会有一些延迟低但丢包的 IP 被排到后面)
|
||||
# 3. 下载测速(从延迟最低的 IP 开始依次下载测速,默认测够 10 个就会停止)
|
||||
# 4. 速度排序(速度从高到低排序)
|
||||
# 5. 输出结果(可依靠参数控制是否输出到命令行(-p 0)/文件(-o ""))
|
||||
# 5. 输出结果(通过参数控制是否输出到命令行(-p 0)或输出到文件(-o ""))
|
||||
```
|
||||
|
||||
测速结果第一行就是**既下载速度最快、又平均延迟最低的最快 IP**!至于拿来干嘛?取决于你~
|
||||
测速结果第一行就是**既下载速度最快、又平均延迟最低的最快 IP**!
|
||||
|
||||
完整结果保存在当前目录下的 `result.csv` 文件中,用**记事本/表格软件**打开,格式如下:
|
||||
|
||||
```
|
||||
IP 地址, 已发送, 已接收, 丢包率, 平均延迟, 下载速度 (MB/s)
|
||||
104.27.200.69, 4, 4, 0.00, 146.23, 28.64
|
||||
104.27.200.69,4,4,0.00,146.23,28.64
|
||||
```
|
||||
|
||||
> _大家可以按自己需求,对完整结果**进一步筛选处理**,或者去看一看进阶使用**指定过滤条件**!_
|
||||
@@ -130,7 +130,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
-n 200
|
||||
延迟测速线程;越多延迟测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000)
|
||||
-t 4
|
||||
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP;(默认 4 次)
|
||||
延迟测速次数;单个 IP 延迟测速的次数;(默认 4 次)
|
||||
-dn 10
|
||||
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10 个)
|
||||
-dt 10
|
||||
@@ -142,15 +142,19 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
|
||||
-httping
|
||||
切换测速模式;延迟测速模式改为 HTTP 协议,所用测试地址为 [-url] 参数;(默认 TCPing)
|
||||
注意:HTTPing 本质上也算一种 网络扫描 行为,因此如果你在服务器上面运行,需要降低并发(-n),否则可能会被一些严格的商家暂停服务。
|
||||
如果你遇到 HTTPing 首次测速可用 IP 数量正常,后续测速越来越少甚至直接为 0,但停一段时间后又恢复了的情况,那么也可能是被 运营商、Cloudflare CDN 认为你在网络扫描而 触发临时限制机制,因此才会过一会儿就恢复了,建议降低并发(-n)减少这种情况的发生。
|
||||
-httping-code 200
|
||||
有效状态代码;HTTPing 延迟测速时网页返回的有效 HTTP 状态码,仅限一个;(默认 200 301 302)
|
||||
-cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD
|
||||
匹配指定地区;地区名为当地机场三字码,英文逗号分隔,仅 HTTPing 模式可用;(默认 所有地区)
|
||||
匹配指定地区;地区名为当地机场三字码,英文逗号分隔,支持小写,支持 Cloudflare、AWS CloudFront,仅 HTTPing 模式可用;(默认 所有地区)
|
||||
|
||||
-tl 200
|
||||
平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms)
|
||||
平均延迟上限;只输出低于指定平均延迟的 IP,各上下限条件可搭配使用;(默认 9999 ms)
|
||||
-tll 40
|
||||
平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 0 ms)
|
||||
平均延迟下限;只输出高于指定平均延迟的 IP;(默认 0 ms)
|
||||
-tlr 0.2
|
||||
丢包几率上限;只输出低于/等于指定丢包率的 IP,范围 0.00~1.00,0 过滤掉任何丢包的 IP;(默认 1.00)
|
||||
-sl 5
|
||||
下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
|
||||
|
||||
@@ -179,6 +183,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
Windows 要指定参数需要在 CMD 中运行,或者把参数添加到快捷方式目标中。
|
||||
|
||||
> **注意**:各参数均有**默认值**,使用默认值的参数是可以省略的(**按需选择**),参数**不分前后顺序**。
|
||||
> **提示**:Windows **PowerShell** 只需把下面命令中的 `CloudflareST.exe` 改为 `.\CloudflareST.exe` 即可。
|
||||
> **提示**:Linux 系统只需要把下面命令中的 `CloudflareST.exe` 改为 `./CloudflareST` 即可。
|
||||
|
||||
****
|
||||
@@ -207,6 +212,8 @@ Windows 要指定参数需要在 CMD 中运行,或者把参数添加到快捷
|
||||
|
||||
> 当然你也可以随便打开一个 CMD 窗口,然后输入如 `cd /d "D:\Program Files\CloudflareST"` 来进入程序目录
|
||||
|
||||
> **提示**:如果用的是 **PowerShell** 只需把命令中的 `CloudflareST.exe` 改为 `.\CloudflareST.exe` 即可。
|
||||
|
||||
</details>
|
||||
|
||||
****
|
||||
@@ -243,13 +250,14 @@ D:\ABC\CloudflareST\CloudflareST.exe -n 500 -t 4 -dn 20 -dt 5 -o " "
|
||||
|
||||
****
|
||||
``` bash
|
||||
# 测速 IPv4 时,需要指定 IPv4 数据文件(-f 默认值就是 ip.txt,所以该参数可省略)
|
||||
# 指定自带的 IPv4 数据文件可测速这些 IPv4 地址(-f 默认值就是 ip.txt,所以该参数可省略)
|
||||
CloudflareST.exe -f ip.txt
|
||||
|
||||
# 测速 IPv6 时,需要指定 IPv6 数据文件(v2.1.0 版本后支持 IPv4+IPv6 混合测速并移除了 -ipv6 参数)
|
||||
# 指定自带的 IPv6 数据文件可测速这些 IPv6 地址
|
||||
# 另外,v2.1.0 版本后支持 IPv4+IPv6 混合测速并移除了 -ipv6 参数,因此一个文件内可以同时包含 IPv4+IPv6 地址
|
||||
CloudflareST.exe -f ipv6.txt
|
||||
|
||||
# 当然你也可以将 IPv4 IPv6 混合在一起测速,也可以直接通过参数指定要测速的 IP
|
||||
# 也可以直接通过参数指定要测速的 IP
|
||||
CloudflareST.exe -ip 1.1.1.1,2606:4700::/32
|
||||
```
|
||||
|
||||
@@ -272,7 +280,9 @@ TCP 协议耗时更短、消耗资源更少,超时时间为 1 秒,该协议
|
||||
HTTP 协议适用于快速测试某域名指向某 IP 时是否可以访问,超时时间为 2 秒。
|
||||
同一个 IP,各协议去 Ping 得到的延迟一般为:**ICMP < TCP < HTTP**,越靠右对丢包等网络波动越敏感。
|
||||
|
||||
> 注意:HTTPing 本质上也算一种**网络扫描**行为,因此如果你在服务器上面运行,需要**降低并发**(`-n`),否则可能会被一些严格的商家暂停服务。
|
||||
> 注意:HTTPing 本质上也算一种**网络扫描**行为,因此如果你在服务器上面运行,需要**降低并发**(`-n`),否则可能会被一些严格的商家暂停服务。如果你遇到 HTTPing 首次测速可用 IP 数量正常,后续测速越来越少甚至直接为 0,但停一段时间后又恢复了的情况,那么也可能是被 运营商、Cloudflare CDN 认为你在网络扫描而**触发临时限制机制**,因此才会过一会儿就恢复了,建议**降低并发**(`-n`)减少这种情况的发生。
|
||||
|
||||
> 另外,本软件 HTTPing 仅获取**响应头(response headers)**,并不获取正文内容(即 URL 文件大小不影响 HTTPing 测试,但如果你还要下载测速的话,那么还是需要一个大文件的),类似于 curl -i 功能。
|
||||
|
||||
``` bash
|
||||
# 只需加上 -httping 参数即可切换到 HTTP 协议延迟测速模式
|
||||
@@ -283,10 +293,11 @@ CloudflareST.exe -httping -httping-code 200
|
||||
|
||||
# 通过 -url 参数来指定 HTTPing 测试地址(可以是任意网页 URL,不局限于具体文件地址)
|
||||
CloudflareST.exe -httping -url https://cf.xiu2.xyz/url
|
||||
# 如果你要 HTTPing 测试其他网站/CDN,那么指定一个该网站/使用该 CDN 的地址(因为软件默认地址是 Cloudflare 的,只能用于测试 Cloudflare 的 IP)
|
||||
|
||||
# 注意:如果测速地址为 HTTP 协议,记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口)
|
||||
# 同理,如果要测速 80 端口,那么也需要加上 -url 参数来指定一个 http:// 协议的地址才行(默认测速地址是 HTTPS 的)
|
||||
CloudflareST.exe -httping -tp 80 -url http://xxx/xxx
|
||||
# 同理,如果要测速 80 端口,那么也需要加上 -url 参数来指定一个 http:// 协议的地址才行(且该地址不会强制重定向至 HTTPS),如果是非 80 443 端口,那么需要确定该下载测速地址是否支持通过该端口访问。
|
||||
CloudflareST.exe -httping -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
|
||||
```
|
||||
|
||||
</details>
|
||||
@@ -301,15 +312,18 @@ CloudflareST.exe -httping -tp 80 -url http://xxx/xxx
|
||||
****
|
||||
|
||||
``` bash
|
||||
# 该功能支持 Cloudflare CDN、AWS CloudFront CDN,且这两个 CDN 的机场三字码是通用的
|
||||
# 注意:如果你要用于筛选 AWS CloudFront CDN 地区,那么要通过 -url 参数指定一个使用该 CDN 的地址(因为软件默认地址是 Cloudflare 的)
|
||||
|
||||
# 指定地区名后,延迟测速后得到的结果就都是指定地区的 IP 了(也可以继续进行下载测速)
|
||||
# 节点地区名为当地 机场三字码,指定多个时用英文逗号分隔
|
||||
# 节点地区名为当地 机场三字码,指定多个时用英文逗号分隔,v2.2.3 版本后支持小写
|
||||
|
||||
CloudflareST.exe -cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD
|
||||
|
||||
# 注意,该参数只有在 HTTPing 延迟测速模式下才可用(因为要访问网页来获得)
|
||||
```
|
||||
|
||||
> Cloudflare 所有节点地区名(机场三字码),请看:https://www.cloudflarestatus.com/
|
||||
> 两个 CDN 机场三字码通用,因此各地区名可见:https://www.cloudflarestatus.com/
|
||||
|
||||
</details>
|
||||
|
||||
@@ -360,6 +374,26 @@ C:\abc\CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
|
||||
|
||||
****
|
||||
|
||||
#### \# 测速其他端口
|
||||
|
||||
<details>
|
||||
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
|
||||
|
||||
****
|
||||
|
||||
``` bash
|
||||
# 如果你想要测速非默认 443 的其他端口,则需要通过 -tp 参数指定(该参数会影响 延迟测速/下载测速 时使用的端口)
|
||||
|
||||
# 如果要延迟测速 80 端口+下载测速(如果 -dd 禁用了下载测速则不需要),那么还需要指定 http:// 协议的下载测速地址才行(且该地址不会强制重定向至 HTTPS,因为那样就变成 443 端口了)
|
||||
CloudflareST.exe -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
|
||||
|
||||
# 如果是非 80 443 的其他端口,那么需要确定你使用的下载测速地址是否支持通过该非标端口访问。
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
****
|
||||
|
||||
#### \# 自定义测速地址
|
||||
|
||||
<details>
|
||||
@@ -373,35 +407,29 @@ C:\abc\CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
|
||||
# 地址要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN
|
||||
CloudflareST.exe -url https://cf.xiu2.xyz/url
|
||||
|
||||
# 注意:如果测速地址为 HTTP 协议,记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口)
|
||||
CloudflareST.exe -tp 80 -url http://xxx/xxx
|
||||
# 注意:如果测速地址为 HTTP 协议(该地址不能强制重定向至 HTTPS),记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口),如果是非 80 443 端口,那么需要确定下载测速地址是否支持通过该端口访问。
|
||||
CloudflareST.exe -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
****
|
||||
|
||||
#### \# 自定义测速条件(指定 延迟/下载速度 的目标范围)
|
||||
#### \# 自定义测速条件(指定 延迟/丢包/下载速度 的目标范围)
|
||||
|
||||
<details>
|
||||
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
|
||||
|
||||
****
|
||||
|
||||
- 指定 **[平均延迟下限]** 条件
|
||||
|
||||
``` bash
|
||||
# 平均延迟下限:40 ms (一般除了移动直连香港外,几乎不存在低于 100ms 的,自行测试适合的下限延迟)
|
||||
# 平均延迟下限和其他的上下限参数一样,都可以单独使用、互相搭配使用!
|
||||
CloudflareST.exe -tll 40
|
||||
```
|
||||
> 注意:延迟测速进度条右边的**可用数量**,仅指延迟测速过程中**未超时的 IP 数量**,和延迟上下限条件无关。
|
||||
|
||||
- 仅指定 **[平均延迟上限]** 条件
|
||||
|
||||
``` bash
|
||||
# 平均延迟上限:200 ms,下载速度下限:0 MB/s,数量:10 个(可选)
|
||||
# 平均延迟上限:200 ms,下载速度下限:0 MB/s
|
||||
# 即找到平均延迟低于 200 ms 的 IP,然后再按延迟从低到高进行 10 次下载测速
|
||||
CloudflareST.exe -tl 200 -dn 10
|
||||
CloudflareST.exe -tl 200
|
||||
```
|
||||
|
||||
> 如果**没有找到一个满足延迟**条件的 IP,那么不会输出任何内容。
|
||||
@@ -416,6 +444,14 @@ CloudflareST.exe -tl 200 -dn 10
|
||||
CloudflareST.exe -tl 200 -dd
|
||||
```
|
||||
|
||||
- 仅指定 **[丢包几率上限]** 条件
|
||||
|
||||
``` bash
|
||||
# 丢包几率上限:0.25
|
||||
# 即找到丢包率低于等于 0.25 的 IP,范围 0.00~1.00,如果 -tlr 0 则代表过滤掉任何丢包的 IP
|
||||
CloudflareST.exe -tlr 0.25
|
||||
```
|
||||
|
||||
****
|
||||
|
||||
- 仅指定 **[下载速度下限]** 条件
|
||||
@@ -446,7 +482,7 @@ CloudflareST.exe -tl 200 -sl 5.6 -dn 10
|
||||
> 如果**没有找到一个满足速度**条件的 IP,那么会忽略条件输出所有 IP 测速结果(方便你下次测速时调整条件)。
|
||||
> 所以建议先不指定条件测速一遍,看看平均延迟和下载速度大概在什么范围,避免指定条件**过低/过高**!
|
||||
|
||||
> 因为Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法使用的,所以下载测速是 0.00。
|
||||
> 因为 Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法使用的,所以下载测速是 0.00。
|
||||
> 运行时可以加上 `-sl 0.01`(下载速度下限),过滤掉**回源 IP**(下载测速低于 0.01MB/s 的结果)。
|
||||
|
||||
</details>
|
||||
@@ -508,7 +544,7 @@ CloudflareST.exe -f 1.txt
|
||||
|
||||
我以前说过,开发该软件项目的目的就是为了通过**改 Hosts 的方式来加速访问使用 Cloudflare CDN 的网站**。
|
||||
|
||||
但就如 [**#8**](https://github.com/XIU2/CloudflareSpeedTest/issues/8) 所说,一个个添加域名到 Hosts 实在**太麻烦**了,于是我就找到了个**一劳永逸**的办法!可以看这个 [**还在一个个添加 Hosts?完美本地加速所有使用 Cloudflare CDN 的网站方法来了!**](https://github.com/XIU2/CloudflareSpeedTest/discussions/71) 和另一个[依靠本地 DNS 服务来修改域名解析 IP 为自选 IP](https://github.com/XIU2/CloudflareSpeedTest/issues/115) 的教程。
|
||||
但就如 [**#8**](https://github.com/XIU2/CloudflareSpeedTest/issues/8) 所说,一个个添加域名到 Hosts 实在**太麻烦**了,于是我就找到了个**一劳永逸**的办法!可以看这个 [**还在一个个添加 Hosts?完美本地加速所有使用 Cloudflare CDN 的网站方法来了!**](https://github.com/XIU2/CloudflareSpeedTest/discussions/71) 和另一个[依靠本地 DNS 服务来修改域名解析 IP 为自选 IP](https://github.com/XIU2/CloudflareSpeedTest/discussions/317) 的教程。
|
||||
|
||||
****
|
||||
|
||||
@@ -516,16 +552,16 @@ CloudflareST.exe -f 1.txt
|
||||
|
||||
考虑到很多人获得最快 Cloudflare CDN IP 后,需要替换 Hosts 文件中的 IP。
|
||||
|
||||
可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/42) 获取 **Windows/Linux 自动更新 Hosts 脚本**!
|
||||
可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/discussions/312) 获取 **Windows/Linux 自动更新 Hosts 脚本**!
|
||||
|
||||
****
|
||||
|
||||
## 问题反馈
|
||||
|
||||
如果你遇到什么问题,可以先去 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues) 里看看是否有别人问过了(记得去看下 [**Closed**](https://github.com/XIU2/CloudflareSpeedTest/issues?q=is%3Aissue+is%3Aclosed) 的)。
|
||||
如果你遇到什么问题,可以先去 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues)、[Discussions](https://github.com/XIU2/CloudflareSpeedTest/discussions) 里看看是否有别人问过了(记得去看下 [**Closed**](https://github.com/XIU2/CloudflareSpeedTest/issues?q=is%3Aissue+is%3Aclosed) 的)。
|
||||
如果没找到类似问题,请新开个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/new) 来告诉我!
|
||||
|
||||
> _有问题请**大胆告诉我**,描述越详细越好(随时可远程协助),如果不说那我怎么去完善功能或~~修复 BUG~~ 呢?!_
|
||||
> **注意**!_与 `反馈问题、功能建议` 无关的,请前往项目内部 论坛 讨论(上面的 `💬 Discussions`_
|
||||
|
||||
****
|
||||
|
||||
@@ -538,15 +574,18 @@ CloudflareST.exe -f 1.txt
|
||||
## 衍生项目
|
||||
|
||||
- _https://github.com/xianshenglu/cloudflare-ip-tester-app_
|
||||
_**CloudflareST 安卓版 APP [#202](https://github.com/XIU2/CloudflareSpeedTest/issues/202)**_
|
||||
_**CloudflareST 安卓版 APP [#202](https://github.com/XIU2/CloudflareSpeedTest/discussions/320)**_
|
||||
|
||||
- _https://github.com/mingxiaoyu/luci-app-cloudflarespeedtest_
|
||||
_**CloudflareST OpenWrt 路由器插件版 [#174](https://github.com/XIU2/CloudflareSpeedTest/issues/174)**_
|
||||
_**CloudflareST OpenWrt 路由器插件版 [#174](https://github.com/XIU2/CloudflareSpeedTest/discussions/319)**_
|
||||
|
||||
- _https://github.com/immortalwrt-collections/openwrt-cdnspeedtest_
|
||||
_**CloudflareST OpenWrt 原生编译版本 [#64](https://github.com/XIU2/CloudflareSpeedTest/discussions/64)**_
|
||||
|
||||
> _此处仅收集了在本项目 Issues 中宣传过的部分 CloudflareST 相关衍生项目,如果有遗漏可以告诉我~_
|
||||
- _https://github.com/hoseinnikkhah/CloudflareSpeedTest-English_
|
||||
_**English language version of CloudflareST (Text language differences only) [#64](https://github.com/XIU2/CloudflareSpeedTest/issues/68)**_
|
||||
|
||||
> _此处仅收集了在本项目中宣传过的部分 CloudflareST 相关衍生项目,如果有遗漏可以告诉我~_
|
||||
|
||||
****
|
||||
|
||||
@@ -559,6 +598,65 @@ _**CloudflareST OpenWrt 原生编译版本 [#64](https://github.com/XIU2/Cloudfl
|
||||
|
||||
****
|
||||
|
||||
## 手动编译
|
||||
|
||||
<details>
|
||||
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
|
||||
|
||||
****
|
||||
|
||||
为了方便,我是在编译的时候将版本号写入代码中的 version 变量,因此你手动编译时,需要像下面这样在 `go build` 命令后面加上 `-ldflags` 参数来指定版本号:
|
||||
|
||||
```bash
|
||||
go build -ldflags "-s -w -X main.version=v2.3.3"
|
||||
# 在 CloudflareSpeedTest 目录中通过命令行(例如 CMD、Bat 脚本)运行该命令,即可编译一个可在和当前设备同样系统、位数、架构的环境下运行的二进制程序(Go 会自动检测你的系统位数、架构)且版本号为 v2.3.3
|
||||
```
|
||||
|
||||
如果想要在 Windows 64位系统下编译**其他系统、架构、位数**,那么需要指定 **GOOS** 和 **GOARCH** 变量。
|
||||
|
||||
例如在 Windows 系统下编译一个适用于 **Linux 系统 amd 架构 64 位**的二进制程序:
|
||||
|
||||
```bat
|
||||
SET GOOS=linux
|
||||
SET GOARCH=amd64
|
||||
go build -ldflags "-s -w -X main.version=v2.3.3"
|
||||
```
|
||||
|
||||
例如在 Linux 系统下编译一个适用于 **Windows 系统 amd 架构 32 位**的二进制程序:
|
||||
|
||||
```bash
|
||||
GOOS=windows
|
||||
GOARCH=386
|
||||
go build -ldflags "-s -w -X main.version=v2.3.3"
|
||||
```
|
||||
|
||||
> 可以运行 `go tool dist list` 来查看当前 Go 版本支持编译哪些组合。
|
||||
|
||||
****
|
||||
|
||||
当然,为了方便批量编译,我会专门指定一个变量为版本号,后续编译直接调用该版本号变量即可。
|
||||
同时,批量编译的话,还需要分开放到不同文件夹才行(或者文件名不同),需要加上 `-o` 参数指定。
|
||||
|
||||
```bat
|
||||
:: Windows 系统下是这样:
|
||||
SET version=v2.3.3
|
||||
SET GOOS=linux
|
||||
SET GOARCH=amd64
|
||||
go build -o Releases\CloudflareST_linux_amd64\CloudflareST -ldflags "-s -w -X main.version=%version%"
|
||||
```
|
||||
|
||||
```bash
|
||||
# Linux 系统下是这样:
|
||||
version=v2.3.3
|
||||
GOOS=windows
|
||||
GOARCH=386
|
||||
go build -o Releases/CloudflareST_windows_386/CloudflareST.exe -ldflags "-s -w -X main.version=${version}"
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
****
|
||||
|
||||
## License
|
||||
|
||||
The GPL-3.0 License.
|
||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
||||
module CloudflareSpeedTest
|
||||
module github.com/XIU2/CloudflareSpeedTest
|
||||
|
||||
go 1.14
|
||||
|
||||
|
||||
19
main.go
19
main.go
@@ -9,8 +9,8 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"CloudflareSpeedTest/task"
|
||||
"CloudflareSpeedTest/utils"
|
||||
"github.com/XIU2/CloudflareSpeedTest/task"
|
||||
"github.com/XIU2/CloudflareSpeedTest/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -28,7 +28,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
-n 200
|
||||
延迟测速线程;越多延迟测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000)
|
||||
-t 4
|
||||
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP;(默认 4 次)
|
||||
延迟测速次数;单个 IP 延迟测速的次数;(默认 4 次)
|
||||
-dn 10
|
||||
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10 个)
|
||||
-dt 10
|
||||
@@ -46,9 +46,11 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
匹配指定地区;地区名为当地机场三字码,英文逗号分隔,仅 HTTPing 模式可用;(默认 所有地区)
|
||||
|
||||
-tl 200
|
||||
平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms)
|
||||
平均延迟上限;只输出低于指定平均延迟的 IP,各上下限条件可搭配使用;(默认 9999 ms)
|
||||
-tll 40
|
||||
平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 0 ms)
|
||||
平均延迟下限;只输出高于指定平均延迟的 IP;(默认 0 ms)
|
||||
-tlr 0.2
|
||||
丢包几率上限;只输出低于/等于指定丢包率的 IP,范围 0.00~1.00,0 过滤掉任何丢包的 IP;(默认 1.00)
|
||||
-sl 5
|
||||
下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
|
||||
|
||||
@@ -72,6 +74,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
打印帮助说明
|
||||
`
|
||||
var minDelay, maxDelay, downloadTime int
|
||||
var maxLossRate float64
|
||||
flag.IntVar(&task.Routines, "n", 200, "延迟测速线程")
|
||||
flag.IntVar(&task.PingTimes, "t", 4, "延迟测速次数")
|
||||
flag.IntVar(&task.TestCount, "dn", 10, "下载测速数量")
|
||||
@@ -85,6 +88,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
|
||||
flag.IntVar(&maxDelay, "tl", 9999, "平均延迟上限")
|
||||
flag.IntVar(&minDelay, "tll", 0, "平均延迟下限")
|
||||
flag.Float64Var(&maxLossRate, "tlr", 1, "丢包几率上限")
|
||||
flag.Float64Var(&task.MinSpeed, "sl", 0, "下载速度下限")
|
||||
|
||||
flag.IntVar(&utils.PrintNum, "p", 10, "显示结果数量")
|
||||
@@ -104,6 +108,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
}
|
||||
utils.InputMaxDelay = time.Duration(maxDelay) * time.Millisecond
|
||||
utils.InputMinDelay = time.Duration(minDelay) * time.Millisecond
|
||||
utils.InputMaxLossRate = float32(maxLossRate)
|
||||
task.Timeout = time.Duration(downloadTime) * time.Second
|
||||
task.HttpingCFColomap = task.MapColoMap()
|
||||
|
||||
@@ -125,8 +130,8 @@ func main() {
|
||||
|
||||
fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version)
|
||||
|
||||
// 开始延迟测速
|
||||
pingData := task.NewPing().Run().FilterDelay()
|
||||
// 开始延迟测速 + 过滤延迟/丢包
|
||||
pingData := task.NewPing().Run().FilterDelay().FilterLossRate()
|
||||
// 开始下载测速
|
||||
speedData := task.TestDownloadSpeed(pingData)
|
||||
utils.ExportCsv(speedData) // 输出文件
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"CloudflareSpeedTest/utils"
|
||||
"github.com/XIU2/CloudflareSpeedTest/utils"
|
||||
|
||||
"github.com/VividCortex/ewma"
|
||||
)
|
||||
@@ -169,6 +169,8 @@ func downloadHandler(ip *net.IPAddr) float64 {
|
||||
if err != nil {
|
||||
if err != io.EOF { // 如果文件下载过程中遇到报错(如 Timeout),且并不是因为文件下载完了,则退出循环(终止测速)
|
||||
break
|
||||
} else if contentLength == -1 { // 文件下载完成 且 文件大小未知,则退出循环(终止测速),例如:https://speed.cloudflare.com/__down?bytes=200000000 这样的,如果在 10 秒内就下载完成了,会导致测速结果明显偏低甚至显示为 0.00(下载速度太快时)
|
||||
break
|
||||
}
|
||||
// 获取上个时间片
|
||||
last_time_slice := timeStart.Add(timeSlice * time.Duration(timeCounter-1))
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -17,6 +18,7 @@ var (
|
||||
HttpingStatusCode int
|
||||
HttpingCFColo string
|
||||
HttpingCFColomap *sync.Map
|
||||
OutRegexp = regexp.MustCompile(`[A-Z]{3}`)
|
||||
)
|
||||
|
||||
// pingReceived pingTotalTime
|
||||
@@ -46,6 +48,7 @@ func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration) {
|
||||
defer resp.Body.Close()
|
||||
|
||||
//fmt.Println("IP:", ip, "StatusCode:", resp.StatusCode, resp.Request.URL)
|
||||
// 如果未指定的 HTTP 状态码,或指定的状态码不合规,则默认只认为 200、301、302 才算 HTTPing 通过
|
||||
if HttpingStatusCode == 0 || HttpingStatusCode < 100 && HttpingStatusCode > 599 {
|
||||
if resp.StatusCode != 200 && resp.StatusCode != 301 && resp.StatusCode != 302 {
|
||||
return 0, 0
|
||||
@@ -58,10 +61,17 @@ func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration) {
|
||||
|
||||
io.Copy(io.Discard, resp.Body)
|
||||
|
||||
// 只有指定了地区才匹配机场三字码
|
||||
if HttpingCFColo != "" {
|
||||
cfRay := resp.Header.Get("CF-RAY")
|
||||
// 通过头部 Server 值判断是 Cloudflare 还是 AWS CloudFront 并设置 cfRay 为各自的机场三字码完整内容
|
||||
cfRay := func() string {
|
||||
if resp.Header.Get("Server") == "cloudflare" {
|
||||
return resp.Header.Get("CF-RAY") // 示例 cf-ray: 7bd32409eda7b020-SJC
|
||||
}
|
||||
return resp.Header.Get("x-amz-cf-pop") // 示例 X-Amz-Cf-Pop: SIN52-P1
|
||||
}()
|
||||
colo := p.getColo(cfRay)
|
||||
if colo == "" {
|
||||
if colo == "" { // 没有匹配到三字码或不符合指定地区则直接结束该 IP 测试
|
||||
return 0, 0
|
||||
}
|
||||
}
|
||||
@@ -102,8 +112,8 @@ func MapColoMap() *sync.Map {
|
||||
if HttpingCFColo == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
colos := strings.Split(HttpingCFColo, ",")
|
||||
// 将参数指定的地区三字码转为大写并格式化
|
||||
colos := strings.Split(strings.ToUpper(HttpingCFColo), ",")
|
||||
colomap := &sync.Map{}
|
||||
for _, colo := range colos {
|
||||
colomap.Store(colo, colo)
|
||||
@@ -115,14 +125,13 @@ func (p *Ping) getColo(b string) string {
|
||||
if b == "" {
|
||||
return ""
|
||||
}
|
||||
idColo := strings.Split(b, "-")
|
||||
|
||||
out := idColo[1]
|
||||
// 正则匹配并返回 机场三字码
|
||||
out := OutRegexp.FindString(b)
|
||||
|
||||
if HttpingCFColomap == nil {
|
||||
return out
|
||||
}
|
||||
|
||||
// 匹配 机场三字码 是否为指定的地区
|
||||
_, ok := HttpingCFColomap.Load(out)
|
||||
if ok {
|
||||
return out
|
||||
|
||||
80
task/ip.go
80
task/ip.go
@@ -49,6 +49,7 @@ func newIPRanges() *IPRanges {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是单独 IP 则加上子网掩码,反之则获取子网掩码(r.mask)
|
||||
func (r *IPRanges) fixIP(ip string) string {
|
||||
// 如果不含有 '/' 则代表不是 IP 段,而是一个单独的 IP,因此需要加上 /32 /128 子网掩码
|
||||
if i := strings.IndexByte(ip, '/'); i < 0 {
|
||||
@@ -64,6 +65,7 @@ func (r *IPRanges) fixIP(ip string) string {
|
||||
return ip
|
||||
}
|
||||
|
||||
// 解析 IP 段,获得 IP、IP 范围、子网掩码
|
||||
func (r *IPRanges) parseCIDR(ip string) {
|
||||
var err error
|
||||
if r.firstIP, r.ipNet, err = net.ParseCIDR(r.fixIP(ip)); err != nil {
|
||||
@@ -98,40 +100,48 @@ func (r *IPRanges) getIPRange() (minIP, hosts byte) {
|
||||
}
|
||||
|
||||
func (r *IPRanges) chooseIPv4() {
|
||||
minIP, hosts := r.getIPRange()
|
||||
for r.ipNet.Contains(r.firstIP) {
|
||||
if TestAll { // 如果是测速全部 IP
|
||||
for i := 0; i <= int(hosts); i++ { // 遍历 IP 最后一段最小值到最大值
|
||||
r.appendIPv4(byte(i) + minIP)
|
||||
if r.mask == "/32" { // 单个 IP 则无需随机,直接加入自身即可
|
||||
r.appendIP(r.firstIP)
|
||||
} else {
|
||||
minIP, hosts := r.getIPRange() // 返回第四段 IP 的最小值及可用数目
|
||||
for r.ipNet.Contains(r.firstIP) { // 只要该 IP 没有超出 IP 网段范围,就继续循环随机
|
||||
if TestAll { // 如果是测速全部 IP
|
||||
for i := 0; i <= int(hosts); i++ { // 遍历 IP 最后一段最小值到最大值
|
||||
r.appendIPv4(byte(i) + minIP)
|
||||
}
|
||||
} else { // 随机 IP 的最后一段 0.0.0.X
|
||||
r.appendIPv4(minIP + randIPEndWith(hosts))
|
||||
}
|
||||
} else { // 随机 IP 的最后一段 0.0.0.X
|
||||
r.appendIPv4(minIP + randIPEndWith(hosts))
|
||||
}
|
||||
r.firstIP[14]++ // 0.0.(X+1).X
|
||||
if r.firstIP[14] == 0 {
|
||||
r.firstIP[13]++ // 0.(X+1).X.X
|
||||
if r.firstIP[13] == 0 {
|
||||
r.firstIP[12]++ // (X+1).X.X.X
|
||||
r.firstIP[14]++ // 0.0.(X+1).X
|
||||
if r.firstIP[14] == 0 {
|
||||
r.firstIP[13]++ // 0.(X+1).X.X
|
||||
if r.firstIP[13] == 0 {
|
||||
r.firstIP[12]++ // (X+1).X.X.X
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *IPRanges) chooseIPv6() {
|
||||
var tempIP uint8
|
||||
for r.ipNet.Contains(r.firstIP) {
|
||||
if r.mask != "/128" {
|
||||
if r.mask == "/128" { // 单个 IP 则无需随机,直接加入自身即可
|
||||
r.appendIP(r.firstIP)
|
||||
} else {
|
||||
var tempIP uint8 // 临时变量,用于记录前一位的值
|
||||
for r.ipNet.Contains(r.firstIP) { // 只要该 IP 没有超出 IP 网段范围,就继续循环随机
|
||||
r.firstIP[15] = randIPEndWith(255) // 随机 IP 的最后一段
|
||||
r.firstIP[14] = randIPEndWith(255) // 随机 IP 的最后一段
|
||||
}
|
||||
targetIP := make([]byte, len(r.firstIP))
|
||||
copy(targetIP, r.firstIP)
|
||||
r.appendIP(targetIP)
|
||||
for i := 13; i >= 0; i-- {
|
||||
tempIP = r.firstIP[i]
|
||||
r.firstIP[i] += randIPEndWith(255)
|
||||
if r.firstIP[i] >= tempIP {
|
||||
break
|
||||
|
||||
targetIP := make([]byte, len(r.firstIP))
|
||||
copy(targetIP, r.firstIP)
|
||||
r.appendIP(targetIP) // 加入 IP 地址池
|
||||
|
||||
for i := 13; i >= 0; i-- { // 从倒数第三位开始往前随机
|
||||
tempIP = r.firstIP[i] // 保存前一位的值
|
||||
r.firstIP[i] += randIPEndWith(255) // 随机 0~255,加到当前位上
|
||||
if r.firstIP[i] >= tempIP { // 如果当前位的值大于等于前一位的值,说明随机成功了,可以退出该循环
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,10 +150,14 @@ func (r *IPRanges) chooseIPv6() {
|
||||
func loadIPRanges() []*net.IPAddr {
|
||||
ranges := newIPRanges()
|
||||
if IPText != "" { // 从参数中获取 IP 段数据
|
||||
IPs := strings.Split(IPText, ",")
|
||||
IPs := strings.Split(IPText, ",") // 以逗号分隔为数组并循环遍历
|
||||
for _, IP := range IPs {
|
||||
ranges.parseCIDR(IP)
|
||||
if isIPv4(IP) {
|
||||
IP = strings.TrimSpace(IP) // 去除首尾的空白字符(空格、制表符、换行符等)
|
||||
if IP == "" { // 跳过空的(即开头、结尾或连续多个 ,, 的情况)
|
||||
continue
|
||||
}
|
||||
ranges.parseCIDR(IP) // 解析 IP 段,获得 IP、IP 范围、子网掩码
|
||||
if isIPv4(IP) { // 生成要测速的所有 IPv4 / IPv6 地址(单个/随机/全部)
|
||||
ranges.chooseIPv4()
|
||||
} else {
|
||||
ranges.chooseIPv6()
|
||||
@@ -159,9 +173,13 @@ func loadIPRanges() []*net.IPAddr {
|
||||
}
|
||||
defer file.Close()
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
ranges.parseCIDR(scanner.Text())
|
||||
if isIPv4(scanner.Text()) {
|
||||
for scanner.Scan() { // 循环遍历文件每一行
|
||||
line := strings.TrimSpace(scanner.Text()) // 去除首尾的空白字符(空格、制表符、换行符等)
|
||||
if line == "" { // 跳过空行
|
||||
continue
|
||||
}
|
||||
ranges.parseCIDR(line) // 解析 IP 段,获得 IP、IP 范围、子网掩码
|
||||
if isIPv4(line) { // 生成要测速的所有 IPv4 / IPv6 地址(单个/随机/全部)
|
||||
ranges.chooseIPv4()
|
||||
} else {
|
||||
ranges.chooseIPv6()
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"CloudflareSpeedTest/utils"
|
||||
"github.com/XIU2/CloudflareSpeedTest/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -64,9 +64,9 @@ func (p *Ping) Run() utils.PingDelaySet {
|
||||
return p.csv
|
||||
}
|
||||
if Httping {
|
||||
fmt.Printf("开始延迟测速(模式:HTTP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
|
||||
fmt.Printf("开始延迟测速(模式:HTTP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms,丢包几率上限:%.2f )\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds(), utils.InputMaxLossRate)
|
||||
} else {
|
||||
fmt.Printf("开始延迟测速(模式:TCP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
|
||||
fmt.Printf("开始延迟测速(模式:TCP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms,丢包几率上限:%.2f )\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds(), utils.InputMaxLossRate)
|
||||
}
|
||||
for _, ip := range p.ips {
|
||||
p.wg.Add(1)
|
||||
|
||||
60
utils/csv.go
60
utils/csv.go
@@ -11,16 +11,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultOutput = "result.csv"
|
||||
maxDelay = 9999 * time.Millisecond
|
||||
minDelay = 0 * time.Millisecond
|
||||
defaultOutput = "result.csv"
|
||||
maxDelay = 9999 * time.Millisecond
|
||||
minDelay = 0 * time.Millisecond
|
||||
maxLossRate float32 = 1.0
|
||||
)
|
||||
|
||||
var (
|
||||
InputMaxDelay = maxDelay
|
||||
InputMinDelay = minDelay
|
||||
Output = defaultOutput
|
||||
PrintNum = 10
|
||||
InputMaxDelay = maxDelay
|
||||
InputMinDelay = minDelay
|
||||
InputMaxLossRate = maxLossRate
|
||||
Output = defaultOutput
|
||||
PrintNum = 10
|
||||
)
|
||||
|
||||
// 是否打印测试结果
|
||||
@@ -42,16 +44,17 @@ type PingData struct {
|
||||
|
||||
type CloudflareIPData struct {
|
||||
*PingData
|
||||
recvRate float32
|
||||
lossRate float32
|
||||
DownloadSpeed float64
|
||||
}
|
||||
|
||||
func (cf *CloudflareIPData) getRecvRate() float32 {
|
||||
if cf.recvRate == 0 {
|
||||
// 计算丢包率
|
||||
func (cf *CloudflareIPData) getLossRate() float32 {
|
||||
if cf.lossRate == 0 {
|
||||
pingLost := cf.Sended - cf.Received
|
||||
cf.recvRate = float32(pingLost) / float32(cf.Sended)
|
||||
cf.lossRate = float32(pingLost) / float32(cf.Sended)
|
||||
}
|
||||
return cf.recvRate
|
||||
return cf.lossRate
|
||||
}
|
||||
|
||||
func (cf *CloudflareIPData) toString() []string {
|
||||
@@ -59,7 +62,7 @@ func (cf *CloudflareIPData) toString() []string {
|
||||
result[0] = cf.IP.String()
|
||||
result[1] = strconv.Itoa(cf.Sended)
|
||||
result[2] = strconv.Itoa(cf.Received)
|
||||
result[3] = strconv.FormatFloat(float64(cf.getRecvRate()), 'f', 2, 32)
|
||||
result[3] = strconv.FormatFloat(float64(cf.getLossRate()), 'f', 2, 32)
|
||||
result[4] = strconv.FormatFloat(cf.Delay.Seconds()*1000, 'f', 2, 32)
|
||||
result[5] = strconv.FormatFloat(cf.DownloadSpeed/1024/1024, 'f', 2, 32)
|
||||
return result
|
||||
@@ -89,17 +92,22 @@ func convertToString(data []CloudflareIPData) [][]string {
|
||||
return result
|
||||
}
|
||||
|
||||
// 延迟丢包排序
|
||||
type PingDelaySet []CloudflareIPData
|
||||
|
||||
// 延迟条件过滤
|
||||
func (s PingDelaySet) FilterDelay() (data PingDelaySet) {
|
||||
if InputMaxDelay > maxDelay || InputMinDelay < minDelay {
|
||||
if InputMaxDelay > maxDelay || InputMinDelay < minDelay { // 当输入的延迟条件不在默认范围内时,不进行过滤
|
||||
return s
|
||||
}
|
||||
if InputMaxDelay == maxDelay && InputMinDelay == minDelay { // 当输入的延迟条件为默认值时,不进行过滤
|
||||
return s
|
||||
}
|
||||
for _, v := range s {
|
||||
if v.Delay > InputMaxDelay { // 平均延迟上限
|
||||
if v.Delay > InputMaxDelay { // 平均延迟上限,延迟大于条件最大值时,后面的数据都不满足条件,直接跳出循环
|
||||
break
|
||||
}
|
||||
if v.Delay < InputMinDelay { // 平均延迟下限
|
||||
if v.Delay < InputMinDelay { // 平均延迟下限,延迟小于条件最小值时,不满足条件,跳过
|
||||
continue
|
||||
}
|
||||
data = append(data, v) // 延迟满足条件时,添加到新数组中
|
||||
@@ -107,18 +115,30 @@ func (s PingDelaySet) FilterDelay() (data PingDelaySet) {
|
||||
return
|
||||
}
|
||||
|
||||
// 丢包条件过滤
|
||||
func (s PingDelaySet) FilterLossRate() (data PingDelaySet) {
|
||||
if InputMaxLossRate >= maxLossRate { // 当输入的丢包条件为默认值时,不进行过滤
|
||||
return s
|
||||
}
|
||||
for _, v := range s {
|
||||
if v.getLossRate() > InputMaxLossRate { // 丢包几率上限
|
||||
break
|
||||
}
|
||||
data = append(data, v) // 丢包率满足条件时,添加到新数组中
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s PingDelaySet) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s PingDelaySet) Less(i, j int) bool {
|
||||
iRate, jRate := s[i].getRecvRate(), s[j].getRecvRate()
|
||||
iRate, jRate := s[i].getLossRate(), s[j].getLossRate()
|
||||
if iRate != jRate {
|
||||
return iRate < jRate
|
||||
}
|
||||
return s[i].Delay < s[j].Delay
|
||||
}
|
||||
|
||||
func (s PingDelaySet) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
@@ -129,11 +149,9 @@ type DownloadSpeedSet []CloudflareIPData
|
||||
func (s DownloadSpeedSet) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
func (s DownloadSpeedSet) Less(i, j int) bool {
|
||||
return s[i].DownloadSpeed > s[j].DownloadSpeed
|
||||
}
|
||||
|
||||
func (s DownloadSpeedSet) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user