mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-03-07 15:15:52 +08:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
479629b84e | ||
|
|
03a1b44e88 | ||
|
|
963dfa68ed | ||
|
|
6417339312 | ||
|
|
edf5dee039 | ||
|
|
12a9fd2ffb | ||
|
|
d73b1374bc | ||
|
|
68899b53fb | ||
|
|
df0b12f018 | ||
|
|
31dbf635a8 | ||
|
|
8e3ee6f2d0 | ||
|
|
4af4d4d3c8 | ||
|
|
7290f04a6b | ||
|
|
9ea310a4d8 | ||
|
|
2dfea884a2 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
dist
|
||||
Releases
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# This is an example goreleaser.yaml file with some sane defaults.
|
||||
# Make sure to check the documentation at http://goreleaser.com
|
||||
before:
|
||||
hooks:
|
||||
# you may remove this if you don't use vgo
|
||||
- go mod tidy
|
||||
# you may remove this if you don't need go generate
|
||||
- go generate ./...
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
id: "CloudflareScanner"
|
||||
binary: "CloudflareScanner"
|
||||
goos:
|
||||
- darwin
|
||||
- freebsd
|
||||
- linux
|
||||
- windows
|
||||
goarch:
|
||||
- 386
|
||||
- amd64
|
||||
- arm
|
||||
#hooks:
|
||||
#post: ./compile.bat "{{ dir .Path }}"
|
||||
archives:
|
||||
- replacements:
|
||||
darwin: MacOS
|
||||
linux: Linux
|
||||
windows: Windows
|
||||
freebsd: Freebsd
|
||||
386: x86
|
||||
amd64: x64
|
||||
files:
|
||||
- ip.txt
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
snapshot:
|
||||
name_template: "v1.1.0"
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func loadFirstIPOfRangeFromFile() []net.IPAddr {
|
||||
file, err := os.Open("ip.txt")
|
||||
func loadFirstIPOfRangeFromFile(ipFile string) []net.IPAddr {
|
||||
file, err := os.Open(ipFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
90
README.md
90
README.md
@@ -1,10 +1,86 @@
|
||||
# CloudflareScanner
|
||||
# XIU2/CloudflareSpeedTest
|
||||
|
||||
本项目可以测试Cloudflare节点接入速度
|
||||
[](https://github.com/XIU2/CloudflareSpeedTest/blob/master/go.mod)
|
||||
[](https://github.com/XIU2/CloudflareSpeedTest/releases/latest)
|
||||
[](https://github.com/XIU2/CloudflareSpeedTest/blob/master/LICENSE)
|
||||
[](https://github.com/XIU2/CloudflareSpeedTest/stargazers)
|
||||
[](https://github.com/XIU2/CloudflareSpeedTest/network/members)
|
||||
|
||||
程序运行完毕后,结果会保存在当前目录的`result.csv`下
|
||||
国外很多网站都在使用 Cloudflare CDN,但分配给中国访客的 IP 并不友好。
|
||||
虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,所以就有了这个软件。
|
||||
|
||||
## 注意事项
|
||||
#### 协程数请不要调过1000,否则容易出现较大误差
|
||||
#### 编译选项为 `go build`
|
||||
#### 您可在release界面下载或编译运行
|
||||
该软件可以**测试 Cloudflare CDN 所有 IP 的延迟和速度,获得最快 IP**!
|
||||
你可以将 IP 添加到 `Hosts` 文件中,以提高访问使用 Cloudflare CDN 服务的国外网站速度!
|
||||
|
||||
****
|
||||
### 快速使用
|
||||
|
||||
1. 下载编译好的可执行文件 [蓝奏云](https://www.lanzoux.com/b0742hkxe) / [Github](https://github.com/XIU2/CloudflareSpeedTest/releases) 并解压。
|
||||
2. 双击运行 `CloudflareST.exe`文件(Windows系统),等待测速...
|
||||
|
||||
测速完毕后,会把结果保存在当前目录下的 `result.csv` 文件中(只输出丢包率 50% 以下的),用记事本打开,排序为**延迟由低到高**,每一列用逗号分隔,分别是:
|
||||
```
|
||||
IP 地址, 测试次数, 成功次数, 成功比率, 平均延迟, 下载速度 (MB/s)
|
||||
104.27.70.18, 4, 4, 1.00, 150.79, 12.89
|
||||
```
|
||||
选择一个平均延迟与下载速度都不错的 IP 放到 `Hosts` 文件中(指向域名)。
|
||||
|
||||
****
|
||||
### 进阶使用
|
||||
|
||||
直接双击运行使用的是默认参数,如果想要测试速度更快、测试结果更全面,可以自定义参数。
|
||||
``` cmd
|
||||
C:\>CloudflareST.exe -h
|
||||
|
||||
CloudflareSpeedTest
|
||||
测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP!
|
||||
https://github.com/XIU2/CloudflareSpeedTest
|
||||
|
||||
参数:
|
||||
-n 500
|
||||
测速线程数量;数值越大速度越快,请勿超过1000(结果误差大);(默认 500)
|
||||
-t 4
|
||||
延迟测速次数;单个 IP 测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
||||
-dn 20
|
||||
下载测速数量;延迟测速并排序后,从最低延迟起测试下载速度的数量,请勿太多(速度慢);(默认 20)
|
||||
-dt 10
|
||||
下载测速时间;单个 IP 测速最长时间,单位:秒;(默认 10)
|
||||
-f ip.txt
|
||||
IP 数据文件;支持相对路径和绝对路径,如果包含空格请前后加上引号;(默认 ip.txt)
|
||||
-dd
|
||||
禁用下载测速;如果带上该参数就是禁用下载测速;(默认 启用)
|
||||
-v
|
||||
打印程序版本
|
||||
-h
|
||||
打印帮助说明
|
||||
|
||||
示例:
|
||||
CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10
|
||||
CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "C:\abc\ip.txt" -dd
|
||||
```
|
||||
|
||||
#### 使用示例
|
||||
|
||||
在 CMD 中运行,或者把启动参数添加到快捷方式中。
|
||||
> **注意:** 不需要通顺加上所有参数,按需选择,参数前后顺序随意。
|
||||
|
||||
``` cmd
|
||||
# CMD 示例
|
||||
CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10
|
||||
```
|
||||
|
||||
``` cmd
|
||||
# 快捷方式示例(右键快捷方式 - 目标)
|
||||
## 如果有引号就放在引号外面,记得引号和 - 之间有空格。
|
||||
"D:\Program Files\CloudflareST\CloudflareST.exe" -n 500 -t 4 -dn 20 -dt 10
|
||||
```
|
||||
|
||||
****
|
||||
### 感谢项目
|
||||
* https://github.com/Spedoske/CloudflareScanner
|
||||
|
||||
意外发现了这个项目,看了之后发现正好解决了我的问题,但是我更喜欢用户命令行方式运行,这样会更方便、有更多使用姿势,于是我临时学了下 Golang 并 Fork 修改了一份命令行方式交互的版本,如果有什么问题可以告诉我,虽然我不一定会~
|
||||
|
||||
****
|
||||
### 许可证
|
||||
The GPL-3.0 License.
|
||||
|
||||
107
main.go
107
main.go
@@ -1,49 +1,79 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/cheggaaa/pb/v3"
|
||||
"os"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cheggaaa/pb/v3"
|
||||
)
|
||||
|
||||
func handleUserInput() {
|
||||
fmt.Println("请输入扫描协程数(数字越大越快,默认400):")
|
||||
fmt.Scanln(&pingRoutine)
|
||||
if pingRoutine <= 0 {
|
||||
pingRoutine = 400
|
||||
}
|
||||
fmt.Println("请输入tcping次数(默认10):")
|
||||
fmt.Scanln(&pingTime)
|
||||
if pingTime <= 0 {
|
||||
pingTime = 10
|
||||
}
|
||||
fmt.Println("请输入要测试的下载节点个数(默认10):")
|
||||
fmt.Scanln(&downloadTestCount)
|
||||
if downloadTestCount <= 0 {
|
||||
downloadTestCount = 10
|
||||
}
|
||||
fmt.Println("请输入下载测试时间(默认10,单位为秒):")
|
||||
var version string
|
||||
var disableDownload bool
|
||||
var ipFile string
|
||||
|
||||
func init() {
|
||||
var downloadSecond int64
|
||||
fmt.Scanln(&downloadSecond)
|
||||
if downloadSecond <= 0 {
|
||||
downloadSecond = 10
|
||||
}
|
||||
var printVersion bool
|
||||
const help = `
|
||||
CloudflareSpeedTest
|
||||
测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP!
|
||||
https://github.com/XIU2/CloudflareSpeedTest
|
||||
|
||||
参数:
|
||||
-n 500
|
||||
测速线程数量;数值越大速度越快,请勿超过1000(结果误差大);(默认 500)
|
||||
-t 4
|
||||
延迟测速次数;单个 IP 测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
||||
-dn 20
|
||||
下载测速数量;延迟测速并排序后,从最低延迟起测试下载速度的数量,请勿太多(速度慢);(默认 20)
|
||||
-dt 10
|
||||
下载测速时间;单个 IP 测速最长时间,单位:秒;(默认 10)
|
||||
-f ip.txt
|
||||
IP 数据文件;支持相对路径和绝对路径,如果包含空格请前后加上引号;(默认 ip.txt)
|
||||
-dd
|
||||
禁用下载测速;如果带上该参数就是禁用下载测速;(默认 启用)
|
||||
-v
|
||||
打印程序版本
|
||||
-h
|
||||
打印帮助说明
|
||||
|
||||
示例:
|
||||
CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10
|
||||
CloudflareST.exe -n 500 -t 4 -dn 20 -dt 10 -f "C:\abc\ip.txt" -dd`
|
||||
|
||||
flag.IntVar(&pingRoutine, "n", 500, "测速线程数量")
|
||||
flag.IntVar(&pingTime, "t", 4, "延迟测速次数")
|
||||
flag.IntVar(&downloadTestCount, "dn", 20, "下载测速数量")
|
||||
flag.Int64Var(&downloadSecond, "dt", 10, "下载测速时间")
|
||||
flag.BoolVar(&disableDownload, "dd", false, "禁用下载测速")
|
||||
flag.StringVar(&ipFile, "f", "ip.txt", "IP 数据文件")
|
||||
flag.BoolVar(&printVersion, "v", false, "打印程序版本")
|
||||
|
||||
downloadTestTime = time.Duration(downloadSecond) * time.Second
|
||||
|
||||
flag.Usage = func() { fmt.Print(help) }
|
||||
flag.Parse()
|
||||
if printVersion {
|
||||
println(version)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
initipEndWith()
|
||||
handleUserInput()
|
||||
ips := loadFirstIPOfRangeFromFile()
|
||||
pingCount := len(ips) * pingTime
|
||||
bar := pb.StartNew(pingCount)
|
||||
initipEndWith() // 随机数
|
||||
failTime = pingTime // 设置接收次数
|
||||
ips := loadFirstIPOfRangeFromFile(ipFile) // 读入IP
|
||||
pingCount := len(ips) * pingTime // 计算进度条总数(IP*测试次数)
|
||||
bar := pb.Full.Start(pingCount) // 进度条总数
|
||||
var wg sync.WaitGroup
|
||||
var mu sync.Mutex
|
||||
var data = make([]CloudflareIPData, 0)
|
||||
|
||||
fmt.Println("开始tcping")
|
||||
fmt.Println("开始延迟测速(TCP):")
|
||||
|
||||
control := make(chan bool, pingRoutine)
|
||||
for _, ip := range ips {
|
||||
@@ -54,14 +84,17 @@ func main() {
|
||||
}
|
||||
wg.Wait()
|
||||
bar.Finish()
|
||||
bar = pb.StartNew(downloadTestCount)
|
||||
sort.Sort(CloudflareIPDataSet(data))
|
||||
fmt.Println("开始下载测速")
|
||||
for i := 0; i < downloadTestCount; i++ {
|
||||
_, speed := DownloadSpeedHandler(data[i].ip)
|
||||
data[i].downloadSpeed = speed
|
||||
bar.Add(1)
|
||||
|
||||
sort.Sort(CloudflareIPDataSet(data)) // 排序
|
||||
if !disableDownload { // 如果禁用下载测速就跳过
|
||||
bar = pb.Simple.Start(downloadTestCount)
|
||||
fmt.Println("开始下载测速:")
|
||||
for i := 0; i < downloadTestCount; i++ {
|
||||
_, speed := DownloadSpeedHandler(data[i].ip)
|
||||
data[i].downloadSpeed = speed
|
||||
bar.Add(1)
|
||||
}
|
||||
bar.Finish()
|
||||
}
|
||||
bar.Finish()
|
||||
ExportCsv("./result.csv", data)
|
||||
ExportCsv("./result.csv", data) // 输出结果
|
||||
}
|
||||
|
||||
16
util.go
16
util.go
@@ -2,13 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"github.com/cheggaaa/pb/v3"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/cheggaaa/pb/v3"
|
||||
)
|
||||
|
||||
type CloudflareIPData struct {
|
||||
@@ -35,7 +36,7 @@ func ExportCsv(filePath string, data []CloudflareIPData) {
|
||||
}
|
||||
defer fp.Close()
|
||||
w := csv.NewWriter(fp) //创建一个新的写入文件流
|
||||
w.Write([]string{"IP Address", "Ping count", "Ping received", "Ping received rate", "Ping time", "Download Speed (MB/s)"})
|
||||
w.Write([]string{"IP 地址", "Ping 发送次数", "Ping 接收次数", "Ping 接收率", "平均延迟", "下载速度 (MB/s)"})
|
||||
w.WriteAll(convertToString(data))
|
||||
w.Flush()
|
||||
}
|
||||
@@ -47,9 +48,9 @@ func (cf *CloudflareIPData) toString() []string {
|
||||
result[0] = cf.ip.String()
|
||||
result[1] = strconv.Itoa(cf.pingCount)
|
||||
result[2] = strconv.Itoa(cf.pingReceived)
|
||||
result[3] = strconv.FormatFloat(float64(cf.getRecvRate()), 'f', 4, 32)
|
||||
result[4] = strconv.FormatFloat(float64(cf.pingTime), 'f', 4, 32)
|
||||
result[5] = strconv.FormatFloat(float64(cf.downloadSpeed)/1024/1024, 'f', 4, 32)
|
||||
result[3] = strconv.FormatFloat(float64(cf.getRecvRate()), 'f', 2, 32)
|
||||
result[4] = strconv.FormatFloat(float64(cf.pingTime), 'f', 2, 32)
|
||||
result[5] = strconv.FormatFloat(float64(cf.downloadSpeed)/1024/1024, 'f', 2, 32)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -84,12 +85,13 @@ var downloadTestCount int
|
||||
|
||||
const defaultTcpPort = 443
|
||||
const tcpConnectTimeout = time.Second * 1
|
||||
const failTime = 4
|
||||
|
||||
var failTime int
|
||||
|
||||
type CloudflareIPDataSet []CloudflareIPData
|
||||
|
||||
func initipEndWith() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
ipEndWith = uint8(rand.Intn(254) + 1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user