mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-03-11 17:35:57 +08:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6449f6a4a | ||
|
|
021914f975 | ||
|
|
ce22f6b2a4 | ||
|
|
81c6a70a5c | ||
|
|
ce15d4741a | ||
|
|
32b5afaa88 | ||
|
|
73362a1d4c | ||
|
|
82cfd0123f | ||
|
|
a6f627f5fb | ||
|
|
12695563d7 | ||
|
|
d8316525ff | ||
|
|
3c8b51db36 | ||
|
|
1ed7fb7726 | ||
|
|
e8c847d2c9 | ||
|
|
eaaaa53c10 | ||
|
|
270dcab04b | ||
|
|
c1ba72b3a3 | ||
|
|
01b105d42d | ||
|
|
e3c0a3a742 | ||
|
|
7f6e374ae4 | ||
|
|
b22e7fd4af | ||
|
|
2e20a7c279 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
script/*.* linguist-language=None
|
||||||
38
README.md
38
README.md
@@ -6,7 +6,7 @@
|
|||||||
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
||||||
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
[](https://github.com/XIU2/CloudflareSpeedTest/)
|
||||||
|
|
||||||
## 前排提醒:[关于下载测速不可用 `0.00 MB/s` 的 情况说明 及 解决方法...](https://github.com/XIU2/CloudflareSpeedTest/issues/168)
|
## 前排提醒:[关于下载测速不稳定/不可用的 情况说明 及 解决方法...](https://github.com/XIU2/CloudflareSpeedTest/issues/168)
|
||||||
|
|
||||||
国外很多网站都在使用 Cloudflare CDN,但分配给中国内地访客的 IP 并不友好(延迟高、丢包多、速度慢)。
|
国外很多网站都在使用 Cloudflare CDN,但分配给中国内地访客的 IP 并不友好(延迟高、丢包多、速度慢)。
|
||||||
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,于是就有了这个软件。
|
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,于是就有了这个软件。
|
||||||
@@ -16,14 +16,14 @@
|
|||||||
> _分享我其他开源项目:[**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" />_
|
> _分享我其他开源项目:[**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" />_
|
> _[**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 IP 段](http://d7uri8nf7uskq.cloudfront.net/tools/list-cloudfront-ips)),但下载测速需自行寻找地址。
|
> 本项目也支持对**其他 CDN / 网站 IP** 延迟测速(如:[AWS CloudFront CDN](https://github.com/XIU2/CloudflareSpeedTest/issues/180)),但下载测速需自行寻找地址。
|
||||||
|
|
||||||
****
|
****
|
||||||
## \# 快速使用
|
## \# 快速使用
|
||||||
|
|
||||||
### 下载运行
|
### 下载运行
|
||||||
|
|
||||||
1. 下载编译好的可执行文件 [蓝奏云](https://pan.lanzouo.com/b0742hkxe) / [Github](https://github.com/XIU2/CloudflareSpeedTest/releases) 并解压。
|
1. 下载编译好的可执行文件 [蓝奏云](https://pan.lanzouv.com/b0742hkxe) / [Github](https://github.com/XIU2/CloudflareSpeedTest/releases) 并解压。
|
||||||
2. 双击运行 `CloudflareST.exe` 文件(Windows 系统),等待测速完成...
|
2. 双击运行 `CloudflareST.exe` 文件(Windows 系统),等待测速完成...
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
@@ -43,9 +43,9 @@ cd CloudflareST
|
|||||||
# 下载 CloudflareST 压缩包(自行根据需求替换 URL 中 [版本号] 和 [文件名])
|
# 下载 CloudflareST 压缩包(自行根据需求替换 URL 中 [版本号] 和 [文件名])
|
||||||
wget -N https://download.fastgit.org/XIU2/CloudflareSpeedTest/releases/download/v2.0.3/CloudflareST_linux_amd64.tar.gz
|
wget -N https://download.fastgit.org/XIU2/CloudflareSpeedTest/releases/download/v2.0.3/CloudflareST_linux_amd64.tar.gz
|
||||||
# 考虑到国内直接从 Github 下载速度很慢,这里替换为镜像站了,如果还是下载很慢/无法下载,那就试试下面这几个镜像:
|
# 考虑到国内直接从 Github 下载速度很慢,这里替换为镜像站了,如果还是下载很慢/无法下载,那就试试下面这几个镜像:
|
||||||
# wget -N https://gh.xiu.workers.dev/https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.0.2/CloudflareST_linux_386.tar.gz
|
# wget -N https://gh.xiu.workers.dev/https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.0.3/CloudflareST_linux_amd64.tar.gz
|
||||||
# wget -N https://ghproxy.com/https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.0.2/CloudflareST_linux_386.tar.gz
|
# wget -N https://ghproxy.com/https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.0.3/CloudflareST_linux_amd64.tar.gz
|
||||||
# 如果下载失败的话,尝试删除 -N 参数(如果是为了更新,则记得提前删除旧压缩包 rm CloudflareST_linux_386.tar.gz )
|
# 如果下载失败的话,尝试删除 -N 参数(如果是为了更新,则记得提前删除旧压缩包 rm CloudflareST_linux_amd64.tar.gz )
|
||||||
|
|
||||||
# 解压(不需要删除旧文件,会直接覆盖,自行根据需求替换 文件名)
|
# 解压(不需要删除旧文件,会直接覆盖,自行根据需求替换 文件名)
|
||||||
tar -zxf CloudflareST_linux_amd64.tar.gz
|
tar -zxf CloudflareST_linux_amd64.tar.gz
|
||||||
@@ -67,8 +67,7 @@ chmod +x CloudflareST
|
|||||||
|
|
||||||
****
|
****
|
||||||
|
|
||||||
> _在**手机**上独立运行 CloudflareST 测速的简单教程:**[Android](https://github.com/XIU2/CloudflareSpeedTest/discussions/61)、[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/issues/151)**_
|
||||||
> _**建议测速时避开晚上高峰期(20:00~24:00)**,否则测速结果会与其他时间**相差很大...**_
|
|
||||||
|
|
||||||
### 结果示例
|
### 结果示例
|
||||||
|
|
||||||
@@ -122,7 +121,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
|
|
||||||
参数:
|
参数:
|
||||||
-n 200
|
-n 200
|
||||||
测速线程数量;越多测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000)
|
测速线程数量;越多测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000 )
|
||||||
-t 4
|
-t 4
|
||||||
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4 次)
|
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4 次)
|
||||||
-tp 443
|
-tp 443
|
||||||
@@ -147,8 +146,6 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
|
写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
|
||||||
-dd
|
-dd
|
||||||
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
|
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
|
||||||
-ipv6
|
|
||||||
IPv6测速模式;确保 IP 段数据文件内只包含 IPv6 IP段,软件不支持同时测速 IPv4+IPv6;(默认 IPv4)
|
|
||||||
-allip
|
-allip
|
||||||
测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 IP 段随机测速一个 IP)
|
测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 IP 段随机测速一个 IP)
|
||||||
-v
|
-v
|
||||||
@@ -220,13 +217,15 @@ D:\ABC\CloudflareST\CloudflareST.exe -n 500 -t 4 -dn 20 -dt 5 -o " "
|
|||||||
|
|
||||||
****
|
****
|
||||||
``` bash
|
``` bash
|
||||||
# 测速 IPv4 时,需要指定 IPv4 数据文件(-f 默认值就是 ip.txt,所以该参数可以省略)
|
# 测速 IPv4 时,需要指定 IPv4 数据文件(-f 默认值就是 ip.txt,所以该参数可省略)
|
||||||
CloudflareST.exe -f ip.txt
|
CloudflareST.exe -f ip.txt
|
||||||
|
|
||||||
# 测速 IPv6 时,需要指定 IPv6 数据文件( ipv6.txt ) 的同时再加上 -ipv6 参数
|
# 测速 IPv6 时,需要指定 IPv6 数据文件( ipv6.txt )
|
||||||
CloudflareST.exe -f ipv6.txt -ipv6
|
CloudflareST.exe -f ipv6.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> 测速 IPv6 时,可能会注意到每次测速数量都不一样,了解原因: [#120](https://github.com/XIU2/CloudflareSpeedTest/issues/120)
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
****
|
****
|
||||||
@@ -430,7 +429,13 @@ CloudflareST.exe -f 1.txt
|
|||||||
如果你遇到什么问题,可以先去 [**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) 里看看是否有别人问过了(记得去看下 [**Closed**](https://github.com/XIU2/CloudflareSpeedTest/issues?q=is%3Aissue+is%3Aclosed) 的)。
|
||||||
如果没找到类似问题,请新开个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/new) 来告诉我!
|
如果没找到类似问题,请新开个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/new) 来告诉我!
|
||||||
|
|
||||||
> _有问题请**大胆告诉我**,描述越详细越好(必要时可远程协助),如果不说那我怎么去完善功能或~~修复 BUG~~ 呢?!_
|
> _有问题请**大胆告诉我**,描述越详细越好(随时可远程协助),如果不说那我怎么去完善功能或~~修复 BUG~~ 呢?!_
|
||||||
|
|
||||||
|
****
|
||||||
|
|
||||||
|
## 赞赏支持
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
****
|
****
|
||||||
|
|
||||||
@@ -444,4 +449,5 @@ CloudflareST.exe -f 1.txt
|
|||||||
****
|
****
|
||||||
|
|
||||||
## License
|
## License
|
||||||
The GPL-3.0 License.
|
|
||||||
|
The GPL-3.0 License.
|
||||||
4
ipv6.txt
4
ipv6.txt
@@ -1,5 +1,7 @@
|
|||||||
2606:4700::/32
|
2606:4700::/32
|
||||||
2606:4700::6810:0/112
|
2606:4700::6810:0/112
|
||||||
|
2606:4700:f1::/96
|
||||||
|
2606:4700:83b0::/96
|
||||||
2606:4700:10::/96
|
2606:4700:10::/96
|
||||||
2606:4700:10::6814:0/112
|
2606:4700:10::6814:0/112
|
||||||
2606:4700:10::ac43:0/112
|
2606:4700:10::ac43:0/112
|
||||||
@@ -8,6 +10,8 @@
|
|||||||
2606:4700:130:436c:6f75::/80
|
2606:4700:130:436c:6f75::/80
|
||||||
2606:4700:130:436c:6f75:6466::/96
|
2606:4700:130:436c:6f75:6466::/96
|
||||||
2606:4700:130:436c:6f75:6466:6c61:0/112
|
2606:4700:130:436c:6f75:6466:6c61:0/112
|
||||||
|
2606:4700:f4::/48
|
||||||
|
2606:4700:9c60::/48
|
||||||
2606:4700:3000::/48
|
2606:4700:3000::/48
|
||||||
2606:4700:3001::/48
|
2606:4700:3001::/48
|
||||||
2606:4700:3002::/48
|
2606:4700:3002::/48
|
||||||
|
|||||||
13
main.go
13
main.go
@@ -51,12 +51,10 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
|
写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
|
||||||
-dd
|
-dd
|
||||||
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
|
禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
|
||||||
-ipv6
|
|
||||||
IPv6测速模式;确保 IP 段数据文件内只包含 IPv6 IP段,软件不支持同时测速 IPv4+IPv6;(默认 IPv4)
|
|
||||||
-allip
|
-allip
|
||||||
测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 IP 段随机测速一个 IP)
|
测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 IP 段随机测速一个 IP)
|
||||||
-v
|
-v
|
||||||
打印程序版本+检查版本更新
|
打印程序版本 + 检查版本更新
|
||||||
-h
|
-h
|
||||||
打印帮助说明
|
打印帮助说明
|
||||||
`
|
`
|
||||||
@@ -70,7 +68,6 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
flag.IntVar(&task.TestCount, "dn", 10, "下载测速数量")
|
flag.IntVar(&task.TestCount, "dn", 10, "下载测速数量")
|
||||||
flag.StringVar(&task.URL, "url", "https://cf.xiu2.xyz/url", "下载测速地址")
|
flag.StringVar(&task.URL, "url", "https://cf.xiu2.xyz/url", "下载测速地址")
|
||||||
flag.BoolVar(&task.Disable, "dd", false, "禁用下载测速")
|
flag.BoolVar(&task.Disable, "dd", false, "禁用下载测速")
|
||||||
flag.BoolVar(&task.IPv6, "ipv6", false, "启用IPv6")
|
|
||||||
flag.BoolVar(&task.TestAll, "allip", false, "测速全部 IP")
|
flag.BoolVar(&task.TestAll, "allip", false, "测速全部 IP")
|
||||||
flag.StringVar(&task.IPFile, "f", "ip.txt", "IP 数据文件")
|
flag.StringVar(&task.IPFile, "f", "ip.txt", "IP 数据文件")
|
||||||
flag.Float64Var(&task.MinSpeed, "sl", 0, "下载速度下限")
|
flag.Float64Var(&task.MinSpeed, "sl", 0, "下载速度下限")
|
||||||
@@ -101,7 +98,6 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
go checkUpdate() // 检查版本更新
|
|
||||||
task.InitRandSeed() // 置随机数种子
|
task.InitRandSeed() // 置随机数种子
|
||||||
|
|
||||||
fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version)
|
fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version)
|
||||||
@@ -110,8 +106,8 @@ func main() {
|
|||||||
pingData := task.NewPing().Run().FilterDelay()
|
pingData := task.NewPing().Run().FilterDelay()
|
||||||
// 开始下载测速
|
// 开始下载测速
|
||||||
speedData := task.TestDownloadSpeed(pingData)
|
speedData := task.TestDownloadSpeed(pingData)
|
||||||
utils.ExportCsv(speedData)
|
utils.ExportCsv(speedData) // 输出文件
|
||||||
speedData.Print(task.IPv6)
|
speedData.Print() // 打印结果
|
||||||
|
|
||||||
if versionNew != "" {
|
if versionNew != "" {
|
||||||
fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew)
|
fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew)
|
||||||
@@ -125,8 +121,7 @@ func endPrint() {
|
|||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
|
if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
|
||||||
fmt.Printf("按下 回车键 或 Ctrl+C 退出。")
|
fmt.Printf("按下 回车键 或 Ctrl+C 退出。")
|
||||||
var pause int
|
fmt.Scanln()
|
||||||
fmt.Scanln(&pause)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,9 +91,11 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getDialContext(ip *net.IPAddr) func(ctx context.Context, network, address string) (net.Conn, error) {
|
func getDialContext(ip *net.IPAddr) func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
fakeSourceAddr := ip.String() + ":" + fmt.Sprintf("%d", TCPPort)
|
var fakeSourceAddr string
|
||||||
if IPv6 { // IPv6 需要加上 []
|
if isIPv4(ip.String()) {
|
||||||
fakeSourceAddr = "[" + ip.String() + "]:" + fmt.Sprintf("%d", TCPPort)
|
fakeSourceAddr = fmt.Sprintf("%s:%d", ip.String(), TCPPort)
|
||||||
|
} else {
|
||||||
|
fakeSourceAddr = fmt.Sprintf("[%s]:%d", ip.String(), TCPPort)
|
||||||
}
|
}
|
||||||
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
return (&net.Dialer{}).DialContext(ctx, network, fakeSourceAddr)
|
return (&net.Dialer{}).DialContext(ctx, network, fakeSourceAddr)
|
||||||
|
|||||||
26
task/ip.go
26
task/ip.go
@@ -14,8 +14,6 @@ import (
|
|||||||
const defaultInputFile = "ip.txt"
|
const defaultInputFile = "ip.txt"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// IPv6 IP version is 6
|
|
||||||
IPv6 = false
|
|
||||||
// TestAll test all ip
|
// TestAll test all ip
|
||||||
TestAll = false
|
TestAll = false
|
||||||
// IPFile is the filename of IP Rangs
|
// IPFile is the filename of IP Rangs
|
||||||
@@ -26,7 +24,14 @@ func InitRandSeed() {
|
|||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isIPv4(ip string) bool {
|
||||||
|
return strings.Contains(ip, ".")
|
||||||
|
}
|
||||||
|
|
||||||
func randIPEndWith(num byte) byte {
|
func randIPEndWith(num byte) byte {
|
||||||
|
if num == 0 { // 对于 /32 这种单独的 IP
|
||||||
|
return byte(0)
|
||||||
|
}
|
||||||
return byte(rand.Intn(int(num)))
|
return byte(rand.Intn(int(num)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,8 +51,9 @@ func newIPRanges() *IPRanges {
|
|||||||
func (r *IPRanges) fixIP(ip string) string {
|
func (r *IPRanges) fixIP(ip string) string {
|
||||||
// 如果不含有 '/' 则代表不是 IP 段,而是一个单独的 IP,因此需要加上 /32 /128 子网掩码
|
// 如果不含有 '/' 则代表不是 IP 段,而是一个单独的 IP,因此需要加上 /32 /128 子网掩码
|
||||||
if i := strings.IndexByte(ip, '/'); i < 0 {
|
if i := strings.IndexByte(ip, '/'); i < 0 {
|
||||||
r.mask = "/32"
|
if isIPv4(ip) {
|
||||||
if IPv6 {
|
r.mask = "/32"
|
||||||
|
} else {
|
||||||
r.mask = "/128"
|
r.mask = "/128"
|
||||||
}
|
}
|
||||||
ip += r.mask
|
ip += r.mask
|
||||||
@@ -86,10 +92,6 @@ func (r *IPRanges) getIPRange() (minIP, hosts byte) {
|
|||||||
hosts = 255
|
hosts = 255
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if total == 0 {
|
|
||||||
hosts = 1
|
|
||||||
return
|
|
||||||
}
|
|
||||||
hosts = byte(total)
|
hosts = byte(total)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -117,8 +119,6 @@ func (r *IPRanges) chooseIPv4() {
|
|||||||
func (r *IPRanges) chooseIPv6() {
|
func (r *IPRanges) chooseIPv6() {
|
||||||
var tempIP uint8
|
var tempIP uint8
|
||||||
for r.ipNet.Contains(r.firstIP) {
|
for r.ipNet.Contains(r.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])
|
|
||||||
if r.mask != "/128" {
|
if r.mask != "/128" {
|
||||||
r.firstIP[15] = randIPEndWith(255) // 随机 IP 的最后一段
|
r.firstIP[15] = randIPEndWith(255) // 随机 IP 的最后一段
|
||||||
r.firstIP[14] = randIPEndWith(255) // 随机 IP 的最后一段
|
r.firstIP[14] = randIPEndWith(255) // 随机 IP 的最后一段
|
||||||
@@ -149,11 +149,11 @@ func loadIPRanges() []*net.IPAddr {
|
|||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
ranges.parseCIDR(scanner.Text())
|
ranges.parseCIDR(scanner.Text())
|
||||||
if IPv6 {
|
if isIPv4(scanner.Text()) {
|
||||||
|
ranges.chooseIPv4()
|
||||||
|
} else {
|
||||||
ranges.chooseIPv6()
|
ranges.chooseIPv6()
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
ranges.chooseIPv4()
|
|
||||||
}
|
}
|
||||||
return ranges.ips
|
return ranges.ips
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,11 +62,7 @@ func (p *Ping) Run() utils.PingDelaySet {
|
|||||||
if len(p.ips) == 0 {
|
if len(p.ips) == 0 {
|
||||||
return p.csv
|
return p.csv
|
||||||
}
|
}
|
||||||
ipVersion := "IPv4"
|
fmt.Printf("开始延迟测速(模式:TCP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
|
||||||
if IPv6 { // IPv6 模式判断
|
|
||||||
ipVersion = "IPv6"
|
|
||||||
}
|
|
||||||
fmt.Printf("开始延迟测速(模式:TCP %s,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", ipVersion, TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
|
|
||||||
for _, ip := range p.ips {
|
for _, ip := range p.ips {
|
||||||
p.wg.Add(1)
|
p.wg.Add(1)
|
||||||
p.control <- false
|
p.control <- false
|
||||||
@@ -87,9 +83,10 @@ func (p *Ping) start(ip *net.IPAddr) {
|
|||||||
//bool connectionSucceed float32 time
|
//bool connectionSucceed float32 time
|
||||||
func (p *Ping) tcping(ip *net.IPAddr) (bool, time.Duration) {
|
func (p *Ping) tcping(ip *net.IPAddr) (bool, time.Duration) {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
fullAddress := fmt.Sprintf("%s:%d", ip.String(), TCPPort)
|
var fullAddress string
|
||||||
//fmt.Println(ip.String())
|
if isIPv4(ip.String()) {
|
||||||
if IPv6 { // IPv6 需要加上 []
|
fullAddress = fmt.Sprintf("%s:%d", ip.String(), TCPPort)
|
||||||
|
} else {
|
||||||
fullAddress = fmt.Sprintf("[%s]:%d", ip.String(), TCPPort)
|
fullAddress = fmt.Sprintf("[%s]:%d", ip.String(), TCPPort)
|
||||||
}
|
}
|
||||||
conn, err := net.DialTimeout("tcp", fullAddress, tcpConnectTimeout)
|
conn, err := net.DialTimeout("tcp", fullAddress, tcpConnectTimeout)
|
||||||
|
|||||||
11
utils/csv.go
11
utils/csv.go
@@ -138,7 +138,7 @@ func (s DownloadSpeedSet) Swap(i, j int) {
|
|||||||
s[i], s[j] = s[j], s[i]
|
s[i], s[j] = s[j], s[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s DownloadSpeedSet) Print(ipv6 bool) {
|
func (s DownloadSpeedSet) Print() {
|
||||||
if NoPrintResult() {
|
if NoPrintResult() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -152,9 +152,12 @@ func (s DownloadSpeedSet) Print(ipv6 bool) {
|
|||||||
}
|
}
|
||||||
headFormat := "%-16s%-5s%-5s%-5s%-6s%-11s\n"
|
headFormat := "%-16s%-5s%-5s%-5s%-6s%-11s\n"
|
||||||
dataFormat := "%-18s%-8s%-8s%-8s%-10s%-15s\n"
|
dataFormat := "%-18s%-8s%-8s%-8s%-10s%-15s\n"
|
||||||
if ipv6 { // IPv6 太长了,所以需要调整一下间隔
|
for i := 0; i < PrintNum; i++ { // 如果要输出的 IP 中包含 IPv6,那么就需要调整一下间隔
|
||||||
headFormat = "%-40s%-5s%-5s%-5s%-6s%-11s\n"
|
if len(dateString[i][0]) > 15 {
|
||||||
dataFormat = "%-42s%-8s%-8s%-8s%-10s%-15s\n"
|
headFormat = "%-40s%-5s%-5s%-5s%-6s%-11s\n"
|
||||||
|
dataFormat = "%-42s%-8s%-8s%-8s%-10s%-15s\n"
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf(headFormat, "IP 地址", "已发送", "已接收", "丢包率", "平均延迟", "下载速度 (MB/s)")
|
fmt.Printf(headFormat, "IP 地址", "已发送", "已接收", "丢包率", "平均延迟", "下载速度 (MB/s)")
|
||||||
for i := 0; i < PrintNum; i++ {
|
for i := 0; i < PrintNum; i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user