mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-03-08 07:35:52 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8264138dd8 | ||
|
|
6cb94db59e | ||
|
|
85923cf335 | ||
|
|
60631a958f | ||
|
|
ea46fc5e04 | ||
|
|
9471094d27 | ||
|
|
be4634ee9d |
84
README.md
84
README.md
@@ -115,7 +115,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
-t 4
|
||||
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
||||
-tp 443
|
||||
延迟测速端口;延迟测速 TCP 协议的端口;(默认 443)
|
||||
指定测速端口;延迟测速/下载测速时使用的端口;(默认 443)
|
||||
-dn 10
|
||||
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10)
|
||||
-dt 10
|
||||
@@ -175,7 +175,16 @@ CloudflareST.exe -f 2.txt -o "" -p 10 -dd
|
||||
# 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录下,如含空格请加上引号)
|
||||
CloudflareST.exe -f 3.txt -o result.txt -dd
|
||||
|
||||
# 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录内的 abc 文件夹下,如含空格请加上引号)
|
||||
# Linux(CloudflareST 程序所在目录内的 abc 文件夹下)
|
||||
./CloudflareST -f abc/3.txt -o abc/result.txt -dd
|
||||
# Windows(注意是反斜杠)
|
||||
CloudflareST.exe -f abc\3.txt -o abc\result.txt -dd
|
||||
|
||||
# 指定 IPv4 数据文件 及 输出结果到文件(绝对路径,即 C:\abc\ 目录下,如含空格请加上引号)
|
||||
# Linux(/abc/ 目录下)
|
||||
./CloudflareST -f /abc/4.txt -o /abc/result.csv -dd
|
||||
# Windows(注意是反斜杠)
|
||||
CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
|
||||
```
|
||||
****
|
||||
@@ -185,6 +194,9 @@ CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
|
||||
# 地址要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN
|
||||
CloudflareST.exe -url https://cf.xiu2.xyz/Github/CloudflareSpeedTest.png
|
||||
# 因为默认下载测速地址的文件大小只有 300MB,如果你速度太快的话,测速结果可能会低于实际速度。
|
||||
|
||||
# 注意:如果下载测速地址为 HTTP 协议,记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口)
|
||||
CloudflareST.exe -tp 80 -url http://xxx/xxx
|
||||
```
|
||||
****
|
||||
#### \# 自定义测速条件
|
||||
@@ -255,6 +267,41 @@ CloudflareST.exe -tl 200 -sl 5.6 -dn 10
|
||||
|
||||
</details>
|
||||
|
||||
****
|
||||
#### \# 单独对一个或多个 IP 测速
|
||||
|
||||
<details>
|
||||
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
|
||||
|
||||
****
|
||||
|
||||
如果要单独**对一个或多个 IP 进行测速**,只需要把这些 IP 按如下格式写入到任意文本文件中,例如:`1.txt`
|
||||
|
||||
```
|
||||
1.1.1.1
|
||||
1.1.1.200
|
||||
1.0.0.1/24
|
||||
```
|
||||
|
||||
> 单个 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 中运行)
|
||||
CloudflareST.exe -f 1.txt
|
||||
|
||||
# Linux 系统
|
||||
./CloudflareST -f 1.txt
|
||||
|
||||
# 对于 1.0.0.1/24 这样的 IP 段只会随机最后一段(1.0.0.1~255),如果要测速该 IP 段中的所有 IP,请加上 -allip 参数。
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
****
|
||||
#### \# Windows 快捷方式如何使用参数
|
||||
|
||||
@@ -274,41 +321,6 @@ D:\ABC\CloudflareST\CloudflareST.exe -n 500 -t 4 -dn 20 -dt 5 -o " "
|
||||
|
||||
</details>
|
||||
|
||||
****
|
||||
#### \# 单独对一个或多个 IP 测速
|
||||
|
||||
<details>
|
||||
<summary><code><strong>「 点击展开 查看内容 」</strong></code></summary>
|
||||
|
||||
****
|
||||
|
||||
如果要单独**对一个或多个 IP 进行测速**,只需要把这些 IP 按如下格式写入到任意文本文件中,例如:`1.txt`
|
||||
|
||||
``` json
|
||||
1.1.1.1
|
||||
1.1.1.200
|
||||
1.0.0.1/24
|
||||
```
|
||||
|
||||
> 自从 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 中运行)
|
||||
CloudflareST.exe -f 1.txt
|
||||
|
||||
# Linux 系统
|
||||
./CloudflareST -f 1.txt
|
||||
|
||||
# 对于 IP 段 1.0.0.1/24 软件只会随机最后一段(1.0.0.1~255),如果要测速该 IP 段中的所有 IP,需要加上 -allip 参数。
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
****
|
||||
#### \# 一劳永逸加速所有使用 Cloudflare CDN 的网站(不需要再一个个添加域名到 Hosts 了)
|
||||
|
||||
|
||||
11
main.go
11
main.go
@@ -30,7 +30,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
-t 4
|
||||
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
||||
-tp 443
|
||||
延迟测速端口;延迟测速 TCP 协议的端口;(默认 443)
|
||||
指定测速端口;延迟测速/下载测速时使用的端口;(默认 443)
|
||||
-dn 10
|
||||
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10)
|
||||
-dt 10
|
||||
@@ -63,7 +63,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
var minDelay, maxDelay, downloadTime int
|
||||
flag.IntVar(&task.Routines, "n", 200, "测速线程数量")
|
||||
flag.IntVar(&task.PingTimes, "t", 4, "延迟测速次数")
|
||||
flag.IntVar(&task.TCPPort, "tp", 443, "延迟测速端口")
|
||||
flag.IntVar(&task.TCPPort, "tp", 443, "指定测速端口")
|
||||
flag.IntVar(&maxDelay, "tl", 9999, "平均延迟上限")
|
||||
flag.IntVar(&minDelay, "tll", 0, "平均延迟下限")
|
||||
flag.IntVar(&downloadTime, "dt", 10, "下载测速时间")
|
||||
@@ -101,7 +101,8 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||
}
|
||||
|
||||
func main() {
|
||||
go checkUpdate() // 检查版本更新
|
||||
go checkUpdate() // 检查版本更新
|
||||
task.InitRandSeed() // 置随机数种子
|
||||
|
||||
fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version)
|
||||
|
||||
@@ -123,7 +124,7 @@ func endPrint() {
|
||||
return
|
||||
}
|
||||
if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
|
||||
fmt.Printf("\n按下 回车键 或 Ctrl+C 退出。")
|
||||
fmt.Printf("按下 回车键 或 Ctrl+C 退出。")
|
||||
var pause int
|
||||
fmt.Scanln(&pause)
|
||||
}
|
||||
@@ -133,7 +134,7 @@ func endPrint() {
|
||||
func checkUpdate() {
|
||||
timeout := 10 * time.Second
|
||||
client := http.Client{Timeout: timeout}
|
||||
res, err := client.Get("https://api.xiuer.pw/ver/cloudflarespeedtest.txt")
|
||||
res, err := client.Get("https://api.xiu2.xyz/ver/cloudflarespeedtest.txt")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSe
|
||||
if len(ipSet) < TestCount || MinSpeed > 0 { // 如果IP数组长度(IP数量) 小于下载测速数量(-dn),则次数修正为IP数
|
||||
testNum = len(ipSet)
|
||||
}
|
||||
if testNum < TestCount {
|
||||
TestCount = testNum
|
||||
}
|
||||
|
||||
fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s,下载测速数量:%d,下载测速队列:%d):\n", MinSpeed, TestCount, testNum)
|
||||
bar := utils.NewBar(TestCount)
|
||||
@@ -88,9 +91,9 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSe
|
||||
}
|
||||
|
||||
func getDialContext(ip *net.IPAddr) func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
fakeSourceAddr := ip.String() + ":443"
|
||||
fakeSourceAddr := ip.String() + ":" + fmt.Sprintf("%d", TCPPort)
|
||||
if IPv6 { // IPv6 需要加上 []
|
||||
fakeSourceAddr = "[" + ip.String() + "]:443"
|
||||
fakeSourceAddr = "[" + ip.String() + "]:" + fmt.Sprintf("%d", TCPPort)
|
||||
}
|
||||
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return (&net.Dialer{}).DialContext(ctx, network, fakeSourceAddr)
|
||||
|
||||
@@ -22,8 +22,11 @@ var (
|
||||
IPFile = defaultInputFile
|
||||
)
|
||||
|
||||
func randIPEndWith(num byte) byte {
|
||||
func InitRandSeed() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
func randIPEndWith(num byte) byte {
|
||||
return byte(rand.Intn(int(num)))
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +161,6 @@ func (s DownloadSpeedSet) Print(ipv6 bool) {
|
||||
fmt.Printf(dataFormat, dateString[i][0], dateString[i][1], dateString[i][2], dateString[i][3], dateString[i][4], dateString[i][5])
|
||||
}
|
||||
if !noOutput() {
|
||||
fmt.Printf("\n完整测速结果已写入 %v 文件,可使用记事本/表格软件查看。", Output)
|
||||
fmt.Printf("\n完整测速结果已写入 %v 文件,可使用记事本/表格软件查看。\n", Output)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user