├── .gitattributes
├── .gitignore
├── const
└── tg.go
├── .github
└── ISSUE_TEMPLATE
│ ├── config.yml
│ ├── 02-featureRequest.yml
│ └── 01-bugReport.yml
├── ip.txt
├── cfip
├── tgbot.go
├── account.go
└── cloudflare_api.go
├── utils
├── progress.go
└── csv.go
├── go.mod
├── config.yaml
├── go.sum
├── task
├── httping.go
├── tcpping.go
├── tcping.go
├── ip.go
└── download.go
├── main.go
├── README.md
├── READMEs.md
└── LICENSE
/.gitattributes:
--------------------------------------------------------------------------------
1 | script/*.* linguist-language=None
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | Releases
3 | *.exe
4 | *.csv
5 |
--------------------------------------------------------------------------------
/const/tg.go:
--------------------------------------------------------------------------------
1 | package _const
2 |
3 | var TGPUSH = ""
4 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: 前往讨论区 (💬 Discussions)
4 | url: https://github.com/XIU2/CloudflareSpeedTest/discussions
5 | about: Issues 仅用于反馈问题、功能建议,其他话题请到 💬 Discussions 发帖讨论(不合适的 Issues 会被转过去
--------------------------------------------------------------------------------
/ip.txt:
--------------------------------------------------------------------------------
1 | 173.245.48.0/20
2 | 103.21.244.0/22
3 | 103.22.200.0/22
4 | 103.31.4.0/22
5 | 141.101.64.0/18
6 | 108.162.192.0/18
7 | 190.93.240.0/20
8 | 188.114.96.0/20
9 | 197.234.240.0/22
10 | 198.41.128.0/17
11 | 162.158.0.0/15
12 | 104.16.0.0/13
13 | 104.24.0.0/14
14 | 172.64.0.0/13
15 | 131.0.72.0/22
--------------------------------------------------------------------------------
/cfip/tgbot.go:
--------------------------------------------------------------------------------
1 | package cfip
2 |
3 | import (
4 | "github.com/go-telegram-bot-api/telegram-bot-api"
5 | )
6 |
7 | func PushTgBot(c string) error {
8 | bot, err := tgbotapi.NewBotAPI("1")
9 | if err != nil {
10 | return err
11 | }
12 | bot.Debug = false
13 | msg := tgbotapi.NewMessage(1, c)
14 | _, err = bot.Send(msg)
15 | if err != nil {
16 | return err
17 | }
18 | return nil
19 | }
20 |
--------------------------------------------------------------------------------
/utils/progress.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | "fmt"
5 | "github.com/cheggaaa/pb/v3"
6 | )
7 |
8 | type Bar struct {
9 | pb *pb.ProgressBar
10 | }
11 |
12 | func NewBar(count int, MyStrStart, MyStrEnd string) *Bar {
13 | tmpl := fmt.Sprintf(`{{counters . }} {{ bar . "[" "-" (cycle . "↖" "↗" "↘" "↙" ) "_" "]"}} %s {{string . "MyStr" | green}} %s `, MyStrStart, MyStrEnd)
14 | bar := pb.ProgressBarTemplate(tmpl).Start(count)
15 | return &Bar{pb: bar}
16 | }
17 |
18 | func (b *Bar) Grow(num int, MyStrVal string) {
19 | b.pb.Set("MyStr", MyStrVal).Add(num)
20 | }
21 |
22 | func (b *Bar) Done() {
23 | b.pb.Finish()
24 | }
25 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module edulx/CloudflareSpeedTest-api
2 |
3 | go 1.19
4 |
5 | require (
6 | github.com/VividCortex/ewma v1.2.0
7 | github.com/cheggaaa/pb/v3 v3.1.2
8 | github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
9 | gopkg.in/yaml.v2 v2.4.0
10 | )
11 |
12 | require (
13 | github.com/fatih/color v1.14.1 // indirect
14 | github.com/mattn/go-colorable v0.1.13 // indirect
15 | github.com/mattn/go-isatty v0.0.17 // indirect
16 | github.com/mattn/go-runewidth v0.0.12 // indirect
17 | github.com/rivo/uniseg v0.2.0 // indirect
18 | github.com/technoweenie/multipartstreamer v1.0.1 // indirect
19 | golang.org/x/sys v0.5.0 // indirect
20 | )
21 |
--------------------------------------------------------------------------------
/config.yaml:
--------------------------------------------------------------------------------
1 | #定时器,单位秒
2 | clock : 10
3 | #是否开启定时器 true开启 false关闭
4 | clock_switch : false
5 | #Cloudflare账号邮箱
6 | tgbot :
7 | #Telegram Bot Token
8 | tgbot_token : 123456789:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
9 | #Telegram Bot Chat ID
10 | tgbot_chat_id : 123456789
11 | #是否开启Telegram Bot通知 true开启 false关闭
12 | switch : false
13 | email : 123456@qq.com
14 | #Cloudflare全局API Key
15 | api_key : d97a4c2aacc8f78e7cfd7ea5df2dfb346a177
16 | #Cloudflare域名ID
17 | zone_id : 9cc56627722e4ac1254b6e659249c658
18 | #域名
19 | domain: 123456.xyz
20 | #子域名
21 | subdomains:
22 | - cf1
23 | - cf2
24 | - cf3
25 | - cf4
26 | - cf5
27 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/02-featureRequest.yml:
--------------------------------------------------------------------------------
1 | name: 功能建议 (Feature request)
2 | description: 有什么建议,或希望添加、完善某个功能...
3 | labels: 功能建议
4 | body:
5 | - type: markdown
6 | attributes:
7 | value: |
8 | 发之前,请先搜下有没有类似的 [Issues](https://github.com/XIU2/CloudflareSpeedTest/issues) (包括[关闭](https://github.com/XIU2/CloudflareSpeedTest/issues?q=is%3Aissue+is%3Aclosed)的),请勿重复发起!
9 |
10 | 另外,不接受**个性化**的功能请求(即 **很少人** 或 **只有你自己** 才会用到的功能)
11 | ****
12 | - type: textarea
13 | id: description
14 | attributes:
15 | label: 功能需求
16 | description: 必填,你要什么样的功能?
17 | placeholder: 请输入...
18 | validations:
19 | required: true
20 | - type: textarea
21 | id: anticipation
22 | attributes:
23 | label: 预期目标
24 | description: 必填,你希望该功能具体是什么样子的?如果能提供 示例/截图/代码 就更好了
25 | placeholder: 请输入...
26 | validations:
27 | required: true
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/01-bugReport.yml:
--------------------------------------------------------------------------------
1 | name: 反馈问题 (Bug report)
2 | description: 软件报错等异常情况,或遇到预期之外的问题...
3 | labels: 反馈问题
4 | body:
5 | - type: markdown
6 | attributes:
7 | value: |
8 | 发之前,请先搜下有没有类似的 [Issues](https://github.com/XIU2/CloudflareSpeedTest/issues) 问题(包括[关闭](https://github.com/XIU2/CloudflareSpeedTest/issues?q=is%3Aissue+is%3Aclosed)的),请勿重复发起!
9 | ****
10 | - type: textarea
11 | id: description
12 | attributes:
13 | label: 问题描述
14 | description: 必填,最好写上 复现问题 的步骤,越详细越好,特别是一些复杂的问题
15 | placeholder: 请输入...
16 | validations:
17 | required: true
18 | - type: input
19 | id: version
20 | attributes:
21 | label: 软件版本
22 | description: 必填,可通过运行软件来获取版本信息(例如 v2.2.2)
23 | placeholder: 请输入...
24 | validations:
25 | required: true
26 | - type: textarea
27 | id: screenshots
28 | attributes:
29 | label: 附加截图
30 | description: 可选,也可以是一些错误代码
31 | placeholder: 可在此粘贴图片,或点击下方 [Attach files by dragging & dropping, selecting or pasting them.] 文字来选择图片...
--------------------------------------------------------------------------------
/cfip/account.go:
--------------------------------------------------------------------------------
1 | package cfip
2 |
3 | import "time"
4 |
5 | type CFR struct {
6 | Result []struct {
7 | Id string `json:"id"`
8 | ZoneId string `json:"zone_id"`
9 | ZoneName string `json:"zone_name"`
10 | Name string `json:"name"`
11 | Type string `json:"type"`
12 | Content string `json:"content"`
13 | Proxiable bool `json:"proxiable"`
14 | Proxied bool `json:"proxied"`
15 | Ttl int `json:"ttl"`
16 | Locked bool `json:"locked"`
17 | Meta struct {
18 | AutoAdded bool `json:"auto_added"`
19 | ManagedByApps bool `json:"managed_by_apps"`
20 | ManagedByArgoTunnel bool `json:"managed_by_argo_tunnel"`
21 | Source string `json:"source"`
22 | } `json:"meta"`
23 | Comment interface{} `json:"comment"`
24 | Tags []interface{} `json:"tags"`
25 | CreatedOn time.Time `json:"created_on"`
26 | ModifiedOn time.Time `json:"modified_on"`
27 | } `json:"result"`
28 | Success bool `json:"success"`
29 | Errors []interface{} `json:"errors"`
30 | Messages []interface{} `json:"messages"`
31 | ResultInfo struct {
32 | Page int `json:"page"`
33 | PerPage int `json:"per_page"`
34 | Count int `json:"count"`
35 | TotalCount int `json:"total_count"`
36 | TotalPages int `json:"total_pages"`
37 | } `json:"result_info"`
38 | }
39 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
2 | github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
3 | github.com/cheggaaa/pb/v3 v3.1.2 h1:FIxT3ZjOj9XJl0U4o2XbEhjFfZl7jCVCDOGq1ZAB7wQ=
4 | github.com/cheggaaa/pb/v3 v3.1.2/go.mod h1:SNjnd0yKcW+kw0brSusraeDd5Bf1zBfxAzTL2ss3yQ4=
5 | github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
6 | github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
7 | github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU=
8 | github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
9 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
10 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
11 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
12 | github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
13 | github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
14 | github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow=
15 | github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
16 | github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
17 | github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
18 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
19 | github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
20 | github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
21 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22 | golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
23 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
24 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
25 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
26 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
27 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
28 |
--------------------------------------------------------------------------------
/task/httping.go:
--------------------------------------------------------------------------------
1 | package task
2 |
3 | import (
4 | //"crypto/tls"
5 | //"fmt"
6 | "io"
7 | "log"
8 | "net"
9 | "net/http"
10 | "strings"
11 | "sync"
12 | "time"
13 | )
14 |
15 | var (
16 | Httping bool
17 | HttpingStatusCode int
18 | HttpingCFColo string
19 | HttpingCFColomap *sync.Map
20 | )
21 |
22 | // pingReceived pingTotalTime
23 | func (p *Ping) httping(ip *net.IPAddr) (int, time.Duration) {
24 | hc := http.Client{
25 | Timeout: time.Second * 2,
26 | Transport: &http.Transport{
27 | DialContext: GetDialContext(ip),
28 | //TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 跳过证书验证
29 | },
30 | CheckRedirect: func(req *http.Request, via []*http.Request) error {
31 | return http.ErrUseLastResponse // 阻止重定向
32 | },
33 | }
34 |
35 | // 先访问一次获得 HTTP 状态码 及 Cloudflare Colo
36 | {
37 | requ, err := http.NewRequest(http.MethodHead, URL, nil)
38 | if err != nil {
39 | return 0, 0
40 | }
41 | requ.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36")
42 | resp, err := hc.Do(requ)
43 | if err != nil {
44 | return 0, 0
45 | }
46 | defer resp.Body.Close()
47 |
48 | //fmt.Println("IP:", ip, "StatusCode:", resp.StatusCode, resp.Request.URL)
49 | if HttpingStatusCode == 0 || HttpingStatusCode < 100 && HttpingStatusCode > 599 {
50 | if resp.StatusCode != 200 && resp.StatusCode != 301 && resp.StatusCode != 302 {
51 | return 0, 0
52 | }
53 | } else {
54 | if resp.StatusCode != HttpingStatusCode {
55 | return 0, 0
56 | }
57 | }
58 |
59 | io.Copy(io.Discard, resp.Body)
60 |
61 | if HttpingCFColo != "" {
62 | cfRay := resp.Header.Get("CF-RAY")
63 | colo := p.getColo(cfRay)
64 | if colo == "" {
65 | return 0, 0
66 | }
67 | }
68 |
69 | }
70 |
71 | // 循环测速计算延迟
72 | success := 0
73 | var delay time.Duration
74 | for i := 0; i < PingTimes; i++ {
75 | requ, err := http.NewRequest(http.MethodHead, URL, nil)
76 | if err != nil {
77 | log.Fatal("意外的错误,情报告:", err)
78 | return 0, 0
79 | }
80 | requ.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36")
81 | if i == PingTimes-1 {
82 | requ.Header.Set("Connection", "close")
83 | }
84 | startTime := time.Now()
85 | resp, err := hc.Do(requ)
86 | if err != nil {
87 | continue
88 | }
89 | success++
90 | io.Copy(io.Discard, resp.Body)
91 | _ = resp.Body.Close()
92 | duration := time.Since(startTime)
93 | delay += duration
94 |
95 | }
96 |
97 | return success, delay
98 |
99 | }
100 |
101 | func MapColoMap() *sync.Map {
102 | if HttpingCFColo == "" {
103 | return nil
104 | }
105 |
106 | colos := strings.Split(HttpingCFColo, ",")
107 | colomap := &sync.Map{}
108 | for _, colo := range colos {
109 | colomap.Store(colo, colo)
110 | }
111 | return colomap
112 | }
113 |
114 | func (p *Ping) getColo(b string) string {
115 | if b == "" {
116 | return ""
117 | }
118 | idColo := strings.Split(b, "-")
119 |
120 | out := idColo[1]
121 |
122 | if HttpingCFColomap == nil {
123 | return out
124 | }
125 |
126 | _, ok := HttpingCFColomap.Load(out)
127 | if ok {
128 | return out
129 | }
130 |
131 | return ""
132 | }
133 |
--------------------------------------------------------------------------------
/task/tcpping.go:
--------------------------------------------------------------------------------
1 | package task
2 |
3 | import (
4 | "edulx/CloudflareSpeedTest-api/utils"
5 | "fmt"
6 | "net"
7 | "sort"
8 | "strconv"
9 | "sync"
10 | "time"
11 | )
12 |
13 | const (
14 | tcpConnectTimeout = time.Second * 1
15 | maxRoutine = 1000
16 | defaultRoutines = 200
17 | defaultPort = 443
18 | defaultPingTimes = 4
19 | )
20 |
21 | var (
22 | Routines = defaultRoutines
23 | TCPPort int = defaultPort
24 | PingTimes int = defaultPingTimes
25 | )
26 |
27 | type Ping struct {
28 | wg *sync.WaitGroup
29 | m *sync.Mutex
30 | ips []*net.IPAddr
31 | csv utils.PingDelaySet
32 | control chan bool
33 | bar *utils.Bar
34 | }
35 |
36 | func checkPingDefault() {
37 | if Routines <= 0 {
38 | Routines = defaultRoutines
39 | }
40 | if TCPPort <= 0 || TCPPort >= 65535 {
41 | TCPPort = defaultPort
42 | }
43 | if PingTimes <= 0 {
44 | PingTimes = defaultPingTimes
45 | }
46 | }
47 |
48 | func NewPing() *Ping {
49 | checkPingDefault()
50 | ips := loadIPRanges()
51 | return &Ping{
52 | wg: &sync.WaitGroup{},
53 | m: &sync.Mutex{},
54 | ips: ips,
55 | csv: make(utils.PingDelaySet, 0),
56 | control: make(chan bool, Routines),
57 | bar: utils.NewBar(len(ips), "可用:", ""),
58 | }
59 | }
60 |
61 | func (p *Ping) Run() utils.PingDelaySet {
62 | if len(p.ips) == 0 {
63 | return p.csv
64 | }
65 | if Httping {
66 | fmt.Printf("开始延迟测速(模式:HTTP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
67 | } else {
68 | fmt.Printf("开始延迟测速(模式:TCP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
69 | }
70 | for _, ip := range p.ips {
71 | p.wg.Add(1)
72 | p.control <- false
73 | go p.start(ip)
74 | }
75 | p.wg.Wait()
76 | p.bar.Done()
77 | sort.Sort(p.csv)
78 | return p.csv
79 | }
80 |
81 | func (p *Ping) start(ip *net.IPAddr) {
82 | defer p.wg.Done()
83 | p.tcpingHandler(ip)
84 | <-p.control
85 | }
86 |
87 | // bool connectionSucceed float32 time
88 | func (p *Ping) tcping(ip *net.IPAddr) (bool, time.Duration) {
89 | startTime := time.Now()
90 | var fullAddress string
91 | if isIPv4(ip.String()) {
92 | fullAddress = fmt.Sprintf("%s:%d", ip.String(), TCPPort)
93 | } else {
94 | fullAddress = fmt.Sprintf("[%s]:%d", ip.String(), TCPPort)
95 | }
96 | conn, err := net.DialTimeout("tcp", fullAddress, tcpConnectTimeout)
97 | if err != nil {
98 | return false, 0
99 | }
100 | defer conn.Close()
101 | duration := time.Since(startTime)
102 | return true, duration
103 | }
104 |
105 | // pingReceived pingTotalTime
106 | func (p *Ping) checkConnection(ip *net.IPAddr) (recv int, totalDelay time.Duration) {
107 | if Httping {
108 | recv, totalDelay = p.httping(ip)
109 | return
110 | }
111 | for i := 0; i < PingTimes; i++ {
112 | if ok, delay := p.tcping(ip); ok {
113 | recv++
114 | totalDelay += delay
115 | }
116 | }
117 | return
118 | }
119 |
120 | func (p *Ping) appendIPData(data *utils.PingData) {
121 | p.m.Lock()
122 | defer p.m.Unlock()
123 | p.csv = append(p.csv, utils.CloudflareIPData{
124 | PingData: data,
125 | })
126 | }
127 |
128 | // handle tcping
129 | func (p *Ping) tcpingHandler(ip *net.IPAddr) {
130 | recv, totalDlay := p.checkConnection(ip)
131 | nowAble := len(p.csv)
132 | if recv != 0 {
133 | nowAble++
134 | }
135 | p.bar.Grow(1, strconv.Itoa(nowAble))
136 | if recv == 0 {
137 | return
138 | }
139 | data := &utils.PingData{
140 | IP: ip,
141 | Sended: PingTimes,
142 | Received: recv,
143 | Delay: totalDlay / time.Duration(recv),
144 | }
145 | p.appendIPData(data)
146 | }
147 |
--------------------------------------------------------------------------------
/task/tcping.go:
--------------------------------------------------------------------------------
1 | package task
2 |
3 | import (
4 | "fmt"
5 | "net"
6 | "sort"
7 | "strconv"
8 | "sync"
9 | "time"
10 |
11 | "github.com/v50-one/CloudflareSpeedTest-api/utils"
12 | )
13 |
14 | const (
15 | tcpConnectTimeout = time.Second * 1
16 | maxRoutine = 1000
17 | defaultRoutines = 200
18 | defaultPort = 443
19 | defaultPingTimes = 4
20 | )
21 |
22 | var (
23 | Routines = defaultRoutines
24 | TCPPort int = defaultPort
25 | PingTimes int = defaultPingTimes
26 | )
27 |
28 | type Ping struct {
29 | wg *sync.WaitGroup
30 | m *sync.Mutex
31 | ips []*net.IPAddr
32 | csv utils.PingDelaySet
33 | control chan bool
34 | bar *utils.Bar
35 | }
36 |
37 | func checkPingDefault() {
38 | if Routines <= 0 {
39 | Routines = defaultRoutines
40 | }
41 | if TCPPort <= 0 || TCPPort >= 65535 {
42 | TCPPort = defaultPort
43 | }
44 | if PingTimes <= 0 {
45 | PingTimes = defaultPingTimes
46 | }
47 | }
48 |
49 | func NewPing() *Ping {
50 | checkPingDefault()
51 | ips := loadIPRanges()
52 | return &Ping{
53 | wg: &sync.WaitGroup{},
54 | m: &sync.Mutex{},
55 | ips: ips,
56 | csv: make(utils.PingDelaySet, 0),
57 | control: make(chan bool, Routines),
58 | bar: utils.NewBar(len(ips), "可用:", ""),
59 | }
60 | }
61 |
62 | func (p *Ping) Run() utils.PingDelaySet {
63 | if len(p.ips) == 0 {
64 | return p.csv
65 | }
66 | if Httping {
67 | fmt.Printf("开始延迟测速(模式:HTTP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
68 | } else {
69 | fmt.Printf("开始延迟测速(模式:TCP,端口:%d,平均延迟上限:%v ms,平均延迟下限:%v ms)\n", TCPPort, utils.InputMaxDelay.Milliseconds(), utils.InputMinDelay.Milliseconds())
70 | }
71 | for _, ip := range p.ips {
72 | p.wg.Add(1)
73 | p.control <- false
74 | go p.start(ip)
75 | }
76 | p.wg.Wait()
77 | p.bar.Done()
78 | sort.Sort(p.csv)
79 | return p.csv
80 | }
81 |
82 | func (p *Ping) start(ip *net.IPAddr) {
83 | defer p.wg.Done()
84 | p.tcpingHandler(ip)
85 | <-p.control
86 | }
87 |
88 | // bool connectionSucceed float32 time
89 | func (p *Ping) tcping(ip *net.IPAddr) (bool, time.Duration) {
90 | startTime := time.Now()
91 | var fullAddress string
92 | if isIPv4(ip.String()) {
93 | fullAddress = fmt.Sprintf("%s:%d", ip.String(), TCPPort)
94 | } else {
95 | fullAddress = fmt.Sprintf("[%s]:%d", ip.String(), TCPPort)
96 | }
97 | conn, err := net.DialTimeout("tcp", fullAddress, tcpConnectTimeout)
98 | if err != nil {
99 | return false, 0
100 | }
101 | defer conn.Close()
102 | duration := time.Since(startTime)
103 | return true, duration
104 | }
105 |
106 | // pingReceived pingTotalTime
107 | func (p *Ping) checkConnection(ip *net.IPAddr) (recv int, totalDelay time.Duration) {
108 | if Httping {
109 | recv, totalDelay = p.httping(ip)
110 | return
111 | }
112 | for i := 0; i < PingTimes; i++ {
113 | if ok, delay := p.tcping(ip); ok {
114 | recv++
115 | totalDelay += delay
116 | }
117 | }
118 | return
119 | }
120 |
121 | func (p *Ping) appendIPData(data *utils.PingData) {
122 | p.m.Lock()
123 | defer p.m.Unlock()
124 | p.csv = append(p.csv, utils.CloudflareIPData{
125 | PingData: data,
126 | })
127 | }
128 |
129 | // handle tcping
130 | func (p *Ping) tcpingHandler(ip *net.IPAddr) {
131 | recv, totalDlay := p.checkConnection(ip)
132 | nowAble := len(p.csv)
133 | if recv != 0 {
134 | nowAble++
135 | }
136 | p.bar.Grow(1, strconv.Itoa(nowAble))
137 | if recv == 0 {
138 | return
139 | }
140 | data := &utils.PingData{
141 | IP: ip,
142 | Sended: PingTimes,
143 | Received: recv,
144 | Delay: totalDlay / time.Duration(recv),
145 | }
146 | p.appendIPData(data)
147 | }
148 |
--------------------------------------------------------------------------------
/task/ip.go:
--------------------------------------------------------------------------------
1 | package task
2 |
3 | import (
4 | "bufio"
5 | "log"
6 | "math/rand"
7 | "net"
8 | "os"
9 | "strconv"
10 | "strings"
11 | "time"
12 | )
13 |
14 | const defaultInputFile = "ip.txt"
15 |
16 | var (
17 | // TestAll test all ip
18 | TestAll = false
19 | // IPFile is the filename of IP Rangs
20 | IPFile = defaultInputFile
21 | IPText string
22 | )
23 |
24 | func InitRandSeed() {
25 | rand.Seed(time.Now().UnixNano())
26 | }
27 |
28 | func isIPv4(ip string) bool {
29 | return strings.Contains(ip, ".")
30 | }
31 |
32 | func randIPEndWith(num byte) byte {
33 | if num == 0 { // 对于 /32 这种单独的 IP
34 | return byte(0)
35 | }
36 | return byte(rand.Intn(int(num)))
37 | }
38 |
39 | type IPRanges struct {
40 | ips []*net.IPAddr
41 | mask string
42 | firstIP net.IP
43 | ipNet *net.IPNet
44 | }
45 |
46 | func newIPRanges() *IPRanges {
47 | return &IPRanges{
48 | ips: make([]*net.IPAddr, 0),
49 | }
50 | }
51 |
52 | func (r *IPRanges) fixIP(ip string) string {
53 | // 如果不含有 '/' 则代表不是 IP 段,而是一个单独的 IP,因此需要加上 /32 /128 子网掩码
54 | if i := strings.IndexByte(ip, '/'); i < 0 {
55 | if isIPv4(ip) {
56 | r.mask = "/32"
57 | } else {
58 | r.mask = "/128"
59 | }
60 | ip += r.mask
61 | } else {
62 | r.mask = ip[i:]
63 | }
64 | return ip
65 | }
66 |
67 | func (r *IPRanges) parseCIDR(ip string) {
68 | var err error
69 | if r.firstIP, r.ipNet, err = net.ParseCIDR(r.fixIP(ip)); err != nil {
70 | log.Fatalln("ParseCIDR err", err)
71 | }
72 | }
73 |
74 | func (r *IPRanges) appendIPv4(d byte) {
75 | r.appendIP(net.IPv4(r.firstIP[12], r.firstIP[13], r.firstIP[14], d))
76 | }
77 |
78 | func (r *IPRanges) appendIP(ip net.IP) {
79 | r.ips = append(r.ips, &net.IPAddr{IP: ip})
80 | }
81 |
82 | // 返回第四段 ip 的最小值及可用数目
83 | func (r *IPRanges) getIPRange() (minIP, hosts byte) {
84 | minIP = r.firstIP[15] & r.ipNet.Mask[3] // IP 第四段最小值
85 |
86 | // 根据子网掩码获取主机数量
87 | m := net.IPv4Mask(255, 255, 255, 255)
88 | for i, v := range r.ipNet.Mask {
89 | m[i] ^= v
90 | }
91 | total, _ := strconv.ParseInt(m.String(), 16, 32) // 总可用 IP 数
92 | if total > 255 { // 矫正 第四段 可用 IP 数
93 | hosts = 255
94 | return
95 | }
96 | hosts = byte(total)
97 | return
98 | }
99 |
100 | func (r *IPRanges) chooseIPv4() {
101 | minIP, hosts := r.getIPRange()
102 | for r.ipNet.Contains(r.firstIP) {
103 | if TestAll { // 如果是测速全部 IP
104 | for i := 0; i <= int(hosts); i++ { // 遍历 IP 最后一段最小值到最大值
105 | r.appendIPv4(byte(i) + minIP)
106 | }
107 | } else { // 随机 IP 的最后一段 0.0.0.X
108 | r.appendIPv4(minIP + randIPEndWith(hosts))
109 | }
110 | r.firstIP[14]++ // 0.0.(X+1).X
111 | if r.firstIP[14] == 0 {
112 | r.firstIP[13]++ // 0.(X+1).X.X
113 | if r.firstIP[13] == 0 {
114 | r.firstIP[12]++ // (X+1).X.X.X
115 | }
116 | }
117 | }
118 | }
119 |
120 | func (r *IPRanges) chooseIPv6() {
121 | var tempIP uint8
122 | for r.ipNet.Contains(r.firstIP) {
123 | if r.mask != "/128" {
124 | r.firstIP[15] = randIPEndWith(255) // 随机 IP 的最后一段
125 | r.firstIP[14] = randIPEndWith(255) // 随机 IP 的最后一段
126 | }
127 | targetIP := make([]byte, len(r.firstIP))
128 | copy(targetIP, r.firstIP)
129 | r.appendIP(targetIP)
130 | for i := 13; i >= 0; i-- {
131 | tempIP = r.firstIP[i]
132 | r.firstIP[i] += randIPEndWith(255)
133 | if r.firstIP[i] >= tempIP {
134 | break
135 | }
136 | }
137 | }
138 | }
139 |
140 | func loadIPRanges() []*net.IPAddr {
141 | ranges := newIPRanges()
142 | if IPText != "" { // 从参数中获取 IP 段数据
143 | IPs := strings.Split(IPText, ",")
144 | for _, IP := range IPs {
145 | ranges.parseCIDR(IP)
146 | if isIPv4(IP) {
147 | ranges.chooseIPv4()
148 | } else {
149 | ranges.chooseIPv6()
150 | }
151 | }
152 | } else { // 从文件中获取 IP 段数据
153 | if IPFile == "" {
154 | IPFile = defaultInputFile
155 | }
156 | file, err := os.Open(IPFile)
157 | if err != nil {
158 | log.Fatal(err)
159 | }
160 | defer file.Close()
161 | scanner := bufio.NewScanner(file)
162 | for scanner.Scan() {
163 | ranges.parseCIDR(scanner.Text())
164 | if isIPv4(scanner.Text()) {
165 | ranges.chooseIPv4()
166 | } else {
167 | ranges.chooseIPv6()
168 | }
169 | }
170 | }
171 | return ranges.ips
172 | }
173 |
--------------------------------------------------------------------------------
/utils/csv.go:
--------------------------------------------------------------------------------
1 | package utils
2 |
3 | import (
4 | _const "edulx/CloudflareSpeedTest-api/const"
5 | "encoding/csv"
6 | "fmt"
7 | "log"
8 | "net"
9 | "os"
10 | "strconv"
11 | "time"
12 | )
13 |
14 | const (
15 | defaultOutput = "result.csv"
16 | maxDelay = 9999 * time.Millisecond
17 | minDelay = 0 * time.Millisecond
18 | )
19 |
20 | var (
21 | InputMaxDelay = maxDelay
22 | InputMinDelay = minDelay
23 | Output = defaultOutput
24 | PrintNum = 10
25 | )
26 |
27 | // 是否打印测试结果
28 | func NoPrintResult() bool {
29 | return PrintNum == 0
30 | }
31 |
32 | // 是否输出到文件
33 | func noOutput() bool {
34 | return Output == "" || Output == " "
35 | }
36 |
37 | type PingData struct {
38 | IP *net.IPAddr
39 | Sended int
40 | Received int
41 | Delay time.Duration
42 | }
43 |
44 | type CloudflareIPData struct {
45 | *PingData
46 | recvRate float32
47 | DownloadSpeed float64
48 | }
49 |
50 | func (cf *CloudflareIPData) getRecvRate() float32 {
51 | if cf.recvRate == 0 {
52 | pingLost := cf.Sended - cf.Received
53 | cf.recvRate = float32(pingLost) / float32(cf.Sended)
54 | }
55 | return cf.recvRate
56 | }
57 |
58 | func (cf *CloudflareIPData) toString() []string {
59 | result := make([]string, 6)
60 | result[0] = cf.IP.String()
61 | result[1] = strconv.Itoa(cf.Sended)
62 | result[2] = strconv.Itoa(cf.Received)
63 | result[3] = strconv.FormatFloat(float64(cf.getRecvRate()), 'f', 2, 32)
64 | result[4] = strconv.FormatFloat(cf.Delay.Seconds()*1000, 'f', 2, 32)
65 | result[5] = strconv.FormatFloat(cf.DownloadSpeed/1024/1024, 'f', 2, 32)
66 | return result
67 | }
68 |
69 | func ExportCsv(data []CloudflareIPData) {
70 | if noOutput() || len(data) == 0 {
71 | return
72 | }
73 | fp, err := os.Create(Output)
74 | if err != nil {
75 | log.Fatalf("创建文件[%s]失败:%v", Output, err)
76 | return
77 | }
78 | defer fp.Close()
79 | w := csv.NewWriter(fp) //创建一个新的写入文件流
80 | _ = w.Write([]string{"IP 地址", "已发送", "已接收", "丢包率", "平均延迟", "下载速度 (MB/s)"})
81 | _ = w.WriteAll(convertToString(data))
82 | w.Flush()
83 | }
84 |
85 | func convertToString(data []CloudflareIPData) [][]string {
86 | result := make([][]string, 0)
87 | for _, v := range data {
88 | result = append(result, v.toString())
89 | }
90 | return result
91 | }
92 |
93 | type PingDelaySet []CloudflareIPData
94 |
95 | func (s PingDelaySet) FilterDelay() (data PingDelaySet) {
96 | if InputMaxDelay > maxDelay || InputMinDelay < minDelay {
97 | return s
98 | }
99 | for _, v := range s {
100 | if v.Delay > InputMaxDelay { // 平均延迟上限
101 | break
102 | }
103 | if v.Delay < InputMinDelay { // 平均延迟下限
104 | continue
105 | }
106 | data = append(data, v) // 延迟满足条件时,添加到新数组中
107 | }
108 | return
109 | }
110 |
111 | func (s PingDelaySet) Len() int {
112 | return len(s)
113 | }
114 |
115 | func (s PingDelaySet) Less(i, j int) bool {
116 | iRate, jRate := s[i].getRecvRate(), s[j].getRecvRate()
117 | if iRate != jRate {
118 | return iRate < jRate
119 | }
120 | return s[i].Delay < s[j].Delay
121 | }
122 |
123 | func (s PingDelaySet) Swap(i, j int) {
124 | s[i], s[j] = s[j], s[i]
125 | }
126 |
127 | // 下载速度排序
128 | type DownloadSpeedSet []CloudflareIPData
129 |
130 | func (s DownloadSpeedSet) Len() int {
131 | return len(s)
132 | }
133 |
134 | func (s DownloadSpeedSet) Less(i, j int) bool {
135 | return s[i].DownloadSpeed > s[j].DownloadSpeed
136 | }
137 |
138 | func (s DownloadSpeedSet) Swap(i, j int) {
139 | s[i], s[j] = s[j], s[i]
140 | }
141 |
142 | func (s DownloadSpeedSet) Print() {
143 | if NoPrintResult() {
144 | return
145 | }
146 | if len(s) <= 0 { // IP数组长度(IP数量) 大于 0 时继续
147 | fmt.Println("\n[信息] 完整测速结果 IP 数量为 0,跳过输出结果。")
148 | return
149 | }
150 | dateString := convertToString(s) // 转为多维数组 [][]String
151 | if len(dateString) < PrintNum { // 如果IP数组长度(IP数量) 小于 打印次数,则次数改为IP数量
152 | PrintNum = len(dateString)
153 | }
154 | headFormat := "%-16s%-5s%-5s%-5s%-6s%-11s\n"
155 | dataFormat := "%-18s%-8s%-8s%-8s%-10s%-15s\n"
156 | for i := 0; i < PrintNum; i++ { // 如果要输出的 IP 中包含 IPv6,那么就需要调整一下间隔
157 | if len(dateString[i][0]) > 15 {
158 | headFormat = "%-40s%-5s%-5s%-5s%-6s%-11s\n"
159 | dataFormat = "%-42s%-8s%-8s%-8s%-10s%-15s\n"
160 | break
161 | }
162 | }
163 | fmt.Printf(headFormat, "IP 地址", "已发送", "已接收", "丢包率", "平均延迟", "下载速度 (MB/s)")
164 | _const.TGPUSH += fmt.Sprintf("\nIP 地址 已发送 已接收 丢包率 平均延迟 下载速度 (MB/s)\n")
165 | for i := 0; i < PrintNum; i++ {
166 | fmt.Printf(dataFormat, dateString[i][0], dateString[i][1], dateString[i][2], dateString[i][3], dateString[i][4], dateString[i][5])
167 | _const.TGPUSH += fmt.Sprintf("%s %s %s %s %s %s\n", dateString[i][0], dateString[i][1], dateString[i][2], dateString[i][3], dateString[i][4], dateString[i][5])
168 | }
169 | if !noOutput() {
170 | fmt.Printf("\n完整测速结果已写入 %v 文件,可使用记事本/表格软件查看。\n", Output)
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/task/download.go:
--------------------------------------------------------------------------------
1 | package task
2 |
3 | import (
4 | "context"
5 | "edulx/CloudflareSpeedTest-api/utils"
6 | "fmt"
7 | "github.com/VividCortex/ewma"
8 | "io"
9 | "net"
10 | "net/http"
11 | "sort"
12 | "strconv"
13 | "time"
14 | )
15 |
16 | const (
17 | bufferSize = 1024
18 | defaultURL = "https://cf.xiu2.xyz/url"
19 | defaultTimeout = 10 * time.Second
20 | defaultDisableDownload = false
21 | defaultTestNum = 10
22 | defaultMinSpeed float64 = 0.0
23 | )
24 |
25 | var (
26 | URL = defaultURL
27 | Timeout = defaultTimeout
28 | Disable = defaultDisableDownload
29 |
30 | TestCount = defaultTestNum
31 | MinSpeed = defaultMinSpeed
32 | BestIp []net.IPAddr
33 | SpeedIp []float64
34 | )
35 |
36 | func checkDownloadDefault() {
37 | if URL == "" {
38 | URL = defaultURL
39 | }
40 | if Timeout <= 0 {
41 | Timeout = defaultTimeout
42 | }
43 | if TestCount <= 0 {
44 | TestCount = defaultTestNum
45 | }
46 | if MinSpeed <= 0.0 {
47 | MinSpeed = defaultMinSpeed
48 | }
49 | }
50 |
51 | func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSet) {
52 | checkDownloadDefault()
53 | if Disable {
54 | return utils.DownloadSpeedSet(ipSet)
55 | }
56 | if len(ipSet) <= 0 { // IP数组长度(IP数量) 大于 0 时才会继续下载测速
57 | fmt.Println("\n[信息] 延迟测速结果 IP 数量为 0,跳过下载测速。")
58 | return
59 | }
60 | testNum := TestCount
61 | if len(ipSet) < TestCount || MinSpeed > 0 { // 如果IP数组长度(IP数量) 小于下载测速数量(-dn),则次数修正为IP数
62 | testNum = len(ipSet)
63 | }
64 | if testNum < TestCount {
65 | TestCount = testNum
66 | }
67 |
68 | fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s,下载测速数量:%d,下载测速队列:%d):\n", MinSpeed, TestCount, testNum)
69 | // 控制 下载测速进度条 与 延迟测速进度条 长度一致(强迫症)
70 | bar_a := len(strconv.Itoa(len(ipSet)))
71 | bar_b := " "
72 | for i := 0; i < bar_a; i++ {
73 | bar_b += " "
74 | }
75 | bar := utils.NewBar(TestCount, bar_b, "")
76 | for i := 0; i < testNum; i++ {
77 | speed := downloadHandler(ipSet[i].IP)
78 | ipSet[i].DownloadSpeed = speed
79 | // 在每个 IP 下载测速后,以 [下载速度下限] 条件过滤结果
80 | if speed >= MinSpeed*1024*1024 {
81 | bar.Grow(1, "")
82 | speedSet = append(speedSet, ipSet[i]) // 高于下载速度下限时,添加到新数组中
83 | BestIp = append(BestIp, *ipSet[i].IP) //将下载速度最快的IP地址添加到BEST_IP数组中
84 | SpeedIp = append(SpeedIp, speed) //将下载速度最快的IP地址的下载速度添加到SPEED_IP数组中
85 | if len(speedSet) == TestCount { // 凑够满足条件的 IP 时(下载测速数量 -dn),就跳出循环
86 | break
87 | }
88 | }
89 | }
90 | bar.Done()
91 | if len(speedSet) == 0 { // 没有符合速度限制的数据,返回所有测试数据
92 | speedSet = utils.DownloadSpeedSet(ipSet)
93 | }
94 | // 按速度排序
95 | sort.Sort(speedSet)
96 | return
97 | }
98 |
99 | func GetDialContext(ip *net.IPAddr) func(ctx context.Context, network, address string) (net.Conn, error) {
100 | var fakeSourceAddr string
101 | if isIPv4(ip.String()) {
102 | fakeSourceAddr = fmt.Sprintf("%s:%d", ip.String(), TCPPort)
103 | } else {
104 | fakeSourceAddr = fmt.Sprintf("[%s]:%d", ip.String(), TCPPort)
105 | }
106 | return func(ctx context.Context, network, address string) (net.Conn, error) {
107 | return (&net.Dialer{}).DialContext(ctx, network, fakeSourceAddr)
108 | }
109 | }
110 |
111 | // return download Speed
112 | func downloadHandler(ip *net.IPAddr) float64 {
113 | client := &http.Client{
114 | Transport: &http.Transport{DialContext: GetDialContext(ip)},
115 | Timeout: Timeout,
116 | CheckRedirect: func(req *http.Request, via []*http.Request) error {
117 | if len(via) > 10 { // 限制最多重定向 10 次
118 | return http.ErrUseLastResponse
119 | }
120 | if req.Header.Get("Referer") == defaultURL { // 当使用默认下载测速地址时,重定向不携带 Referer
121 | req.Header.Del("Referer")
122 | }
123 | return nil
124 | },
125 | }
126 | req, err := http.NewRequest("GET", URL, nil)
127 | if err != nil {
128 | return 0.0
129 | }
130 |
131 | req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36")
132 |
133 | response, err := client.Do(req)
134 | if err != nil {
135 | return 0.0
136 | }
137 | defer response.Body.Close()
138 | if response.StatusCode != 200 {
139 | return 0.0
140 | }
141 | timeStart := time.Now() // 开始时间(当前)
142 | timeEnd := timeStart.Add(Timeout) // 加上下载测速时间得到的结束时间
143 |
144 | contentLength := response.ContentLength // 文件大小
145 | buffer := make([]byte, bufferSize)
146 |
147 | var (
148 | contentRead int64 = 0
149 | timeSlice = Timeout / 100
150 | timeCounter = 1
151 | lastContentRead int64 = 0
152 | )
153 |
154 | var nextTime = timeStart.Add(timeSlice * time.Duration(timeCounter))
155 | e := ewma.NewMovingAverage()
156 |
157 | // 循环计算,如果文件下载完了(两者相等),则退出循环(终止测速)
158 | for contentLength != contentRead {
159 | currentTime := time.Now()
160 | if currentTime.After(nextTime) {
161 | timeCounter++
162 | nextTime = timeStart.Add(timeSlice * time.Duration(timeCounter))
163 | e.Add(float64(contentRead - lastContentRead))
164 | lastContentRead = contentRead
165 | }
166 | // 如果超出下载测速时间,则退出循环(终止测速)
167 | if currentTime.After(timeEnd) {
168 | break
169 | }
170 | bufferRead, err := response.Body.Read(buffer)
171 | if err != nil {
172 | if err != io.EOF { // 如果文件下载过程中遇到报错(如 Timeout),且并不是因为文件下载完了,则退出循环(终止测速)
173 | break
174 | } else if contentLength == -1 { // 文件下载完成 且 文件大小未知,则退出循环(终止测速),例如:https://speed.cloudflare.com/__down?bytes=200000000 这样的,如果在 10 秒内就下载完成了,会导致测速结果明显偏低甚至显示为 0.00(下载速度太快时)
175 | break
176 | }
177 | // 获取上个时间片
178 | last_time_slice := timeStart.Add(timeSlice * time.Duration(timeCounter-1))
179 | // 下载数据量 / (用当前时间 - 上个时间片/ 时间片)
180 | e.Add(float64(contentRead-lastContentRead) / (float64(currentTime.Sub(last_time_slice)) / float64(timeSlice)))
181 | }
182 | contentRead += int64(bufferRead)
183 | }
184 | return e.Value() / (Timeout.Seconds() / 120)
185 | }
186 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "edulx/CloudflareSpeedTest-api/cfip"
5 | _const "edulx/CloudflareSpeedTest-api/const"
6 | "edulx/CloudflareSpeedTest-api/task"
7 | "edulx/CloudflareSpeedTest-api/utils"
8 | "flag"
9 | "fmt"
10 | "io"
11 | "io/ioutil"
12 | "net/http"
13 | "os"
14 | "runtime"
15 | "time"
16 | )
17 |
18 | var (
19 | version, versionNew string
20 | )
21 |
22 | func init() {
23 | var printVersion bool
24 |
25 | var help = `
26 | CloudflareSpeedTest ` + version + `
27 | 测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP (IPv4+IPv6)!
28 | https://github.com/XIU2/CloudflareSpeedTest
29 |
30 | 参数:
31 | -n 200
32 | 延迟测速线程;越多延迟测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000)
33 | -t 4
34 | 延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP;(默认 4 次)
35 | -dn 10
36 | 下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10 个)
37 | -dt 10
38 | 下载测速时间;单个 IP 下载测速最长时间,不能太短;(默认 10 秒)
39 | -tp 443
40 | 指定测速端口;延迟测速/下载测速时使用的端口;(默认 443 端口)
41 | -url https://cf.xiu2.xyz/url
42 | 指定测速地址;延迟测速(HTTPing)/下载测速时使用的地址,默认地址不保证可用性,建议自建;
43 |
44 | -httping
45 | 切换测速模式;延迟测速模式改为 HTTP 协议,所用测试地址为 [-url] 参数;(默认 TCPing)
46 | -httping-code 200
47 | 有效状态代码;HTTPing 延迟测速时网页返回的有效 HTTP 状态码,仅限一个;(默认 200 301 302)
48 | -cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD
49 | 匹配指定地区;地区名为当地机场三字码,英文逗号分隔,仅 HTTPing 模式可用;(默认 所有地区)
50 |
51 | -tl 200
52 | 平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms)
53 | -tll 40
54 | 平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 0 ms)
55 | -sl 5
56 | 下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
57 |
58 | -p 10
59 | 显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 10 个)
60 | -f ip.txt
61 | IP段数据文件;如路径含有空格请加上引号;支持其他 CDN IP段;(默认 ip.txt)
62 | -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32
63 | 指定IP段数据;直接通过参数指定要测速的 IP 段数据,英文逗号分隔;(默认 空)
64 | -o result.csv
65 | 写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
66 |
67 | -dd
68 | 禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
69 | -allip
70 | 测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 /24 段随机测速一个 IP)
71 |
72 | -v
73 | 打印程序版本 + 检查版本更新
74 | -h
75 | 打印帮助说明
76 | `
77 | var minDelay, maxDelay, downloadTime int
78 | flag.IntVar(&task.Routines, "n", 200, "延迟测速线程")
79 | flag.IntVar(&task.PingTimes, "t", 4, "延迟测速次数")
80 | flag.IntVar(&task.TestCount, "dn", 10, "下载测速数量")
81 | flag.IntVar(&downloadTime, "dt", 10, "下载测速时间")
82 | flag.IntVar(&task.TCPPort, "tp", 443, "指定测速端口")
83 | flag.StringVar(&task.URL, "url", "https://cf.xiu2.xyz/url", "指定测速地址")
84 |
85 | flag.BoolVar(&task.Httping, "httping", false, "切换测速模式")
86 | flag.IntVar(&task.HttpingStatusCode, "httping-code", 0, "有效状态代码")
87 | flag.StringVar(&task.HttpingCFColo, "cfcolo", "", "匹配指定地区")
88 |
89 | flag.IntVar(&maxDelay, "tl", 300, "平均延迟上限")
90 | flag.IntVar(&minDelay, "tll", 10, "平均延迟下限")
91 | flag.Float64Var(&task.MinSpeed, "sl", 1, "下载速度下限")
92 | flag.IntVar(&utils.PrintNum, "p", 10, "显示结果数量")
93 | flag.StringVar(&task.IPFile, "f", "ip.txt", "IP段数据文件")
94 | flag.StringVar(&task.IPText, "ip", "", "指定IP段数据")
95 | flag.StringVar(&utils.Output, "o", "result.csv", "输出结果文件")
96 |
97 | flag.BoolVar(&task.Disable, "dd", false, "禁用下载测速")
98 | flag.BoolVar(&task.TestAll, "allip", false, "测速全部 IP")
99 |
100 | flag.BoolVar(&printVersion, "v", false, "打印程序版本")
101 | flag.Usage = func() { fmt.Print(help) }
102 | flag.Parse()
103 |
104 | if task.MinSpeed > 0 && time.Duration(maxDelay)*time.Millisecond == utils.InputMaxDelay {
105 | fmt.Println("[小提示] 在使用 [-sl] 参数时,建议搭配 [-tl] 参数,以避免因凑不够 [-dn] 数量而一直测速...")
106 | }
107 | utils.InputMaxDelay = time.Duration(maxDelay) * time.Millisecond
108 | utils.InputMinDelay = time.Duration(minDelay) * time.Millisecond
109 | task.Timeout = time.Duration(downloadTime) * time.Second
110 | task.HttpingCFColomap = task.MapColoMap()
111 |
112 | if printVersion {
113 | println(version)
114 | fmt.Println("检查版本更新中...")
115 | checkUpdate()
116 | if versionNew != "" {
117 | fmt.Printf("*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***", versionNew)
118 | } else {
119 | fmt.Println("当前为最新版本 [" + version + "]!")
120 | }
121 | os.Exit(0)
122 | }
123 | }
124 |
125 | func main() {
126 | err := cfip.C.ReadYaml()
127 | if err != nil {
128 | fmt.Println("配置文件读取失败,请检查配置文件是否存在或者配置文件是否正确")
129 | return
130 | }
131 | if cfip.C.ClockSwitch == true {
132 | if cfip.C.Clock > 0 {
133 | fmt.Println("已开启定时任务,任务间隔为", float64(cfip.C.Clock)/60, "分钟")
134 | timer()
135 | } else {
136 | fmt.Println("间隔不符合规范,请重新设置")
137 | }
138 |
139 | } else {
140 | Run()
141 | endPrint()
142 | }
143 |
144 | }
145 |
146 | func endPrint() {
147 | if utils.NoPrintResult() {
148 | return
149 | }
150 | if runtime.GOOS == "windows" { // 如果是 Windows 系统,则需要按下 回车键 或 Ctrl+C 退出(避免通过双击运行时,测速完毕后直接关闭)
151 | fmt.Printf("按下 回车键 或 Ctrl+C 退出。")
152 | _, err := fmt.Scanln()
153 | if err != nil {
154 | return
155 | }
156 | }
157 | }
158 |
159 | // 检查更新
160 | func checkUpdate() {
161 | timeout := 10 * time.Second
162 | client := http.Client{Timeout: timeout}
163 | res, err := client.Get("https://api.xiu2.xyz/ver/cloudflarespeedtest.txt")
164 | if err != nil {
165 | return
166 | }
167 | // 读取资源数据 body: []byte
168 | body, err := ioutil.ReadAll(res.Body)
169 | if err != nil {
170 | return
171 | }
172 | // 关闭资源流
173 | defer func(Body io.ReadCloser) {
174 | err := Body.Close()
175 | if err != nil {
176 |
177 | }
178 | }(res.Body)
179 | if string(body) != version {
180 | versionNew = string(body)
181 | }
182 | }
183 | func Run() {
184 | task.InitRandSeed() // 置随机数种子
185 |
186 | fmt.Printf("# XIU2/CloudflareSpeedTest %s \n\n", version)
187 | fmt.Println("来自v50-one的修改版,感谢原作者")
188 | // 开始延迟测速
189 | pingData := task.NewPing().Run().FilterDelay()
190 | // 开始下载测速
191 | speedData := task.TestDownloadSpeed(pingData)
192 | utils.ExportCsv(speedData) // 输出文件
193 | speedData.Print() // 打印结果
194 |
195 | if versionNew != "" {
196 | fmt.Printf("\n*** 发现新版本 [%s]!请前往 [https://github.com/XIU2/CloudflareSpeedTest] 更新! ***\n", versionNew)
197 | }
198 |
199 | cfip.C.UpdateDomain(task.BestIp, task.SpeedIp) // 更新域名解析记录
200 | err := cfip.PushTgBot(_const.TGPUSH)
201 | if err != nil {
202 | return
203 | } // 推送到tg机器人
204 |
205 | }
206 |
207 | // 定时函数
208 | func timer() {
209 | for {
210 | Run()
211 | duration := time.Duration(cfip.C.Clock)
212 | fmt.Println("下次执行时间:", time.Now().Add(time.Second*duration).Format("2006-01-02 15:04:05"))
213 | time.Sleep(time.Second * duration)
214 | //等待执行
215 | }
216 | }
217 |
--------------------------------------------------------------------------------
/cfip/cloudflare_api.go:
--------------------------------------------------------------------------------
1 | package cfip
2 |
3 | import (
4 | "crypto/tls"
5 | _const "edulx/CloudflareSpeedTest-api/const"
6 | "edulx/CloudflareSpeedTest-api/task"
7 | "encoding/json"
8 | "errors"
9 | "fmt"
10 | "gopkg.in/yaml.v2"
11 | "io"
12 | "io/ioutil"
13 | "net"
14 | "net/http"
15 | "strconv"
16 | "strings"
17 | "time"
18 | )
19 |
20 | type CloudflareAPI struct {
21 | Clock int `yaml:"clock"`
22 | ClockSwitch bool `yaml:"clock_switch"`
23 | TGbot struct {
24 | TGbotToken string `yaml:"tgbot_token"`
25 | TGbotChatID string `yaml:"tgbot_chat_id"`
26 | Switch bool `yaml:"switch"`
27 | } `yaml:"tgbot"`
28 | Email string `yaml:"email"`
29 | ApiKeys string `yaml:"api_key"`
30 | ZoneId string `yaml:"zone_id"`
31 | Domain string `yaml:"domain"`
32 | SubDomain []string `yaml:"subdomains"`
33 | }
34 |
35 | var C CloudflareAPI
36 |
37 | // ReadYaml 读取yaml文件
38 | func (c *CloudflareAPI) ReadYaml() error {
39 | //读取yaml文件
40 | yamlFile, err := ioutil.ReadFile("config.yaml")
41 | if err != nil {
42 | return err
43 | }
44 | err = yaml.Unmarshal(yamlFile, &C)
45 | if err != nil {
46 | return err
47 | }
48 | if C.Email == "" || C.ApiKeys == "" || C.ZoneId == "" || C.Domain == "" || len(C.SubDomain) == 0 {
49 | fmt.Println("请检查config.yaml配置文件是否正确")
50 | _const.TGPUSH += "请检查config.yaml配置文件是否正确\n"
51 | return errors.New("请检查config.yaml配置文件是否正确")
52 | }
53 | return nil
54 | }
55 |
56 | // GetDomain 调用cloudflare的api查询对应的域名
57 | func (c *CloudflareAPI) GetDomain(ip net.IPAddr) (CFR, error) {
58 | url := "https://api.cloudflare.com/client/v4/zones/" + c.ZoneId + "/dns_records?page=1&per_page=20&order=type&direction=asc"
59 | client := &http.Client{
60 | Timeout: time.Second * 30,
61 | Transport: &http.Transport{
62 | DialContext: task.GetDialContext(&ip),
63 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 跳过证书验证
64 | },
65 | CheckRedirect: func(req *http.Request, via []*http.Request) error {
66 | return http.ErrUseLastResponse // 阻止重定向
67 | },
68 | }
69 | req, err := http.NewRequest("GET", url, nil)
70 | if err != nil {
71 | return CFR{}, err
72 | }
73 | req.Header.Add("X-Auth-Email", c.Email)
74 | req.Header.Add("X-Auth-Key", c.ApiKeys)
75 | req.Header.Add("Content-Type", "application/json")
76 | res, err := client.Do(req)
77 | if err != nil {
78 | return CFR{}, err
79 | }
80 | defer func(Body io.ReadCloser) {
81 | err := Body.Close()
82 | if err != nil {
83 |
84 | }
85 | }(res.Body)
86 | body, err := io.ReadAll(res.Body)
87 | if err != nil {
88 | return CFR{}, err
89 | }
90 | var s CFR
91 | err = json.Unmarshal(body, &s)
92 | if err != nil {
93 | return CFR{}, err
94 | }
95 | if s.Success == false {
96 | return CFR{}, errors.New("域名信息获取失败")
97 | }
98 | return s, nil
99 | }
100 |
101 | // GetDomainUuid 筛选出对应的域名
102 | func (c *CloudflareAPI) GetDomainUuid(ip net.IPAddr) (map[string]string, error) {
103 | s, err := c.GetDomain(ip)
104 | if err != nil {
105 | return nil, err
106 | }
107 | if s.Success == false || s.Errors == nil {
108 | return nil, err
109 | }
110 | mp := make(map[string]string)
111 | for _, v := range s.Result {
112 | mp[strings.Split(v.Name, ".")[0]] = v.Id
113 | }
114 | return mp, nil
115 | }
116 |
117 | // SortIp 根据速度对ip进行排序从大到小
118 | func (c *CloudflareAPI) SortIp(ip []net.IPAddr, speed []float64) []net.IPAddr {
119 | for i := 0; i < len(speed); i++ {
120 | for j := i + 1; j < len(speed); j++ {
121 | if speed[i] < speed[j] {
122 | speed[i], speed[j] = speed[j], speed[i]
123 | ip[i], ip[j] = ip[j], ip[i]
124 | }
125 | }
126 | }
127 | return ip
128 | }
129 |
130 | // UpdateDomain 更新域名
131 | func (c *CloudflareAPI) UpdateDomain(ip []net.IPAddr, speed []float64) {
132 | if len(ip) < len(c.SubDomain) {
133 | fmt.Println("ip地址和域名数量不匹配")
134 | _const.TGPUSH += "ip地址和域名数量不匹配\n"
135 | return
136 | }
137 | err := c.ReadYaml()
138 | if err != nil {
139 | return
140 | }
141 | var s map[string]string
142 | for i := 0; i <= len(ip); i++ {
143 | if i == len(ip) {
144 | fmt.Println("域名信息获取失败,结束重试")
145 | _const.TGPUSH += "域名信息获取失败,结束重试\n"
146 | return
147 | }
148 | s, err = c.GetDomainUuid(ip[i])
149 | if err == nil {
150 | break
151 | }
152 | fmt.Println("域名信息第" + strconv.Itoa(i+1) + "次获取失败,正在进行下一次重试")
153 | }
154 |
155 | ip = c.SortIp(ip, speed)
156 | for i, v := range c.SubDomain {
157 | if i >= len(ip) {
158 | break
159 | }
160 | if s[v] == "" {
161 | fmt.Println("域名:" + v + "." + c.Domain + "不存在")
162 | for k := 0; k <= len(ip); k++ {
163 | if k == len(ip) {
164 | fmt.Println("域名" + v + "." + c.Domain + "创建失败 IP:" + ip[k].String())
165 | _const.TGPUSH += "域名" + v + "." + c.Domain + "创建失败 IP:" + ip[k].String() + "\n"
166 | break
167 | }
168 | err := c.CreateDomain(v, ip[i], ip[k])
169 | if err == nil {
170 | fmt.Println("域名" + v + "." + c.Domain + "创建成功 IP:" + ip[k].String())
171 | _const.TGPUSH += "域名" + v + "." + c.Domain + "创建成功 IP:" + ip[k].String() + "\n"
172 | break
173 | }
174 | fmt.Println("域名" + v + "." + c.Domain + "第" + strconv.Itoa(k+1) + "次创建失败,正在进行下一次重试")
175 | }
176 |
177 | continue
178 | }
179 | for t := 0; t <= len(ip); t++ {
180 | if t == len(ip) {
181 | fmt.Println("域名" + v + "." + c.Domain + "更新失败 IP:" + ip[i].String())
182 | _const.TGPUSH += "域名" + v + "." + c.Domain + "更新失败 IP:" + ip[i].String() + "\n"
183 | break
184 | }
185 | err := c.PUTDomains(ip[i], v, ip[t], s[v])
186 | if err == nil {
187 | fmt.Println("域名" + v + "." + c.Domain + "更新成功 IP:" + ip[i].String())
188 | _const.TGPUSH += "域名" + v + "." + c.Domain + "更新成功 IP:" + ip[i].String() + "\n"
189 | break
190 | }
191 | fmt.Println("域名" + v + "." + c.Domain + "第" + strconv.Itoa(t+1) + "次更新失败,正在进行下一次重试")
192 | }
193 | }
194 | }
195 | func (c *CloudflareAPI) PUTDomains(ip net.IPAddr, subdomain string, ips net.IPAddr, domainid string) error {
196 | url := "https://api.cloudflare.com/client/v4/zones/" + c.ZoneId + "/dns_records/" + domainid
197 | method := "PUT"
198 | payload := strings.NewReader(`{"type":"A","name":"` + subdomain + `.` + c.Domain + `","content":"` + ip.String() + `","ttl":60,"proxied":false}`)
199 | client := &http.Client{
200 | Timeout: time.Second * 30,
201 | Transport: &http.Transport{
202 | DialContext: task.GetDialContext(&ips),
203 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 跳过证书验证
204 | },
205 | CheckRedirect: func(req *http.Request, via []*http.Request) error {
206 | return http.ErrUseLastResponse // 阻止重定向
207 | },
208 | }
209 | req, err := http.NewRequest(method, url, payload)
210 | if err != nil {
211 | return err
212 | }
213 | req.Header.Add("X-Auth-Email", c.Email)
214 | req.Header.Add("X-Auth-Key", c.ApiKeys)
215 | req.Header.Add("Content-Type", "application/json")
216 | res, err := client.Do(req)
217 | if err != nil {
218 | return err
219 | }
220 | body, err := io.ReadAll(res.Body)
221 | defer func(Body io.ReadCloser) {
222 | err := Body.Close()
223 | if err != nil {
224 | fmt.Println(err.Error())
225 | }
226 | }(res.Body)
227 | if err != nil {
228 | return err
229 | }
230 | var s map[string]interface{}
231 | err = json.Unmarshal(body, &s)
232 | if err != nil {
233 | return err
234 | }
235 | if s["success"] == false {
236 |
237 | return errors.New("更新失败")
238 | } else {
239 | return nil
240 | }
241 | }
242 |
243 | // CreateDomain 创建域名解析
244 | func (c *CloudflareAPI) CreateDomain(subdomain string, ip net.IPAddr, ips net.IPAddr) error {
245 | err := c.ReadYaml()
246 | if err != nil {
247 | return err
248 | }
249 | url := "https://api.cloudflare.com/client/v4/zones/" + c.ZoneId + "/dns_records"
250 | method := "POST"
251 | payload := strings.NewReader(`{"type":"A","name":"` + subdomain + `.` + c.Domain + `","content":"` + ip.String() + `","ttl":60,"proxied":false}`)
252 | client := &http.Client{
253 | Timeout: time.Second * 30,
254 | Transport: &http.Transport{
255 | DialContext: task.GetDialContext(&ips),
256 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 跳过证书验证
257 | },
258 | CheckRedirect: func(req *http.Request, via []*http.Request) error {
259 | return http.ErrUseLastResponse // 阻止重定向
260 | }}
261 | req, err := http.NewRequest(method, url, payload)
262 | if err != nil {
263 | return err
264 | }
265 | req.Header.Add("X-Auth-Email", c.Email)
266 | req.Header.Add("X-Auth-Key", c.ApiKeys)
267 | req.Header.Add("Content-Type", "application/json")
268 | res, err := client.Do(req)
269 | if err != nil {
270 | return err
271 | }
272 | body, err := io.ReadAll(res.Body)
273 | defer func(Body io.ReadCloser) {
274 | err := Body.Close()
275 | if err != nil {
276 | fmt.Println(err.Error())
277 | }
278 | }(res.Body)
279 | if err != nil {
280 | return err
281 | }
282 | var s map[string]interface{}
283 | err = json.Unmarshal(body, &s)
284 | if err != nil {
285 | return err
286 | }
287 | if s["success"] == false {
288 | return errors.New("创建失败")
289 | } else {
290 | return nil
291 | }
292 |
293 | }
294 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # v50-one/CloudflareSpeedTest-api
2 | ## Sponsor
3 | We are proudly sponsored by DartNode. DartNode supports our project by providing [mention the specific support they offer, such as infrastructure, services, etc.].
4 | websize:https://dartnode.com
5 |
6 | [](https://dartnode.com)
7 |
8 | Please consider supporting DartNode as they are not only supporting us but also contributing to the open-source community.
9 |
10 | ## 本项目是基于XIU2/CloudflareSpeedTest 改版而来
11 | ## 本改版只是在测速的基础上添加了将优选出来的IP通过调用Cloudflare的api来实现将域名解析到对应的优选ip
12 | # config.yaml 为调用api的配置文件
13 | # 以下为原版教程
14 |
15 |
16 | # XIU2/CloudflareSpeedTest
17 | [](https://github.com/XIU2/CloudflareSpeedTest/)
18 | [](https://github.com/XIU2/CloudflareSpeedTest/releases/latest)
19 | [](https://github.com/XIU2/CloudflareSpeedTest/)
20 | [](https://github.com/XIU2/CloudflareSpeedTest/)
21 | [](https://github.com/XIU2/CloudflareSpeedTest/)
22 |
23 | 国外很多网站都在使用 Cloudflare CDN,但分配给中国内地访客的 IP 并不友好(延迟高、丢包多、速度慢)。
24 | 虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,于是就有了这个软件。
25 |
26 | **「自选优选 IP」测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**!好用的话**点个`⭐`鼓励一下叭~**
27 |
28 | > _分享我其他开源项目:[**TrackersList.com** - 全网热门 BT Tracker 列表!有效提高 BT 下载速度~](https://github.com/XIU2/TrackersListCollection)
_
29 | > _[**UserScript** - 🐵 Github 高速下载、知乎增强、自动无缝翻页、护眼模式 等十几个**油猴脚本**!](https://github.com/XIU2/UserScript)
_
30 |
31 | > 本项目也支持对**其他 CDN / 网站 IP** 延迟测速(如:[CloudFront](https://github.com/XIU2/CloudflareSpeedTest/discussions/304)、[Gcore](https://github.com/XIU2/CloudflareSpeedTest/discussions/303) CDN),但下载测速需自行寻找地址
32 |
33 | > 对于**代理套 Cloudflare CDN** 的用户,须知这应为**备用方案**,而不应该是**唯一方案**,请勿过度依赖 [#217](https://github.com/XIU2/CloudflareSpeedTest/issues/217) [#188](https://github.com/XIU2/CloudflareSpeedTest/issues/188)
34 |
35 | ****
36 | ## \# 快速使用
37 |
38 | ### 下载运行
39 |
40 | 1. 下载编译好的可执行文件
41 | 2. 双击运行 `CloudflareST.exe` 文件(Windows 系统),等待测速完成...
42 |
43 |
44 | 「 点击查看 Linux 系统下的使用示例 」
45 |
46 | ****
47 |
48 | 以下命令仅为示例,版本号和文件名请前往 [**Releases**](https:/ 查看。
49 |
50 | ``` yaml
51 | # 如果是第一次使用,则建议创建新文件夹(后续更新时,跳过该步骤)
52 | mkdir CloudflareST
53 |
54 | # 进入文件夹(后续更新,只需要从这里重复下面的下载、解压命令即可)
55 | cd CloudflareST
56 |
57 | # 下载 CloudflareST 压缩包(自行根据需求替换 URL 中 [版本号] 和 [文件名])
58 | wget -N https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.2.2/CloudflareST_linux_amd64.tar.gz
59 | # 如果你是在国内服务器上下载,那么请使用下面这几个镜像加速:
60 | # wget -N https://download.fastgit.org/XIU2/CloudflareSpeedTest/releases/download/v2.2.2/CloudflareST_linux_amd64.tar.gz
61 | # wget -N https://ghproxy.com/https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.2.2/CloudflareST_linux_amd64.tar.gz
62 | # 如果下载失败的话,尝试删除 -N 参数(如果是为了更新,则记得提前删除旧压缩包 rm CloudflareST_linux_amd64.tar.gz )
63 |
64 | # 解压(不需要删除旧文件,会直接覆盖,自行根据需求替换 文件名)
65 | tar -zxf CloudflareST_linux_amd64.tar.gz
66 |
67 | # 赋予执行权限
68 | chmod +x CloudflareST
69 |
70 | # 运行(不带参数)
71 | ./CloudflareST
72 |
73 | # 运行(带参数示例)
74 | ./CloudflareST -dd -tll 90
75 | ```
76 |
77 | > 如果平**均延迟非常低**(如 0.xx),则说明 CloudflareST **测速时走了代理**,请先关闭代理软件后再测速。
78 | > 如果在**路由器**上运行,建议先关闭路由器内的代理(或将其排除),否则测速结果可能会**不准确/无法使用**。
79 |
80 |
81 |
82 | ****
83 |
84 | > _在**手机**上独立运行 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)**_
85 |
86 | ### 结果示例
87 |
88 | 测速完毕后,默认会显示**最快的 10 个 IP**,示例:
89 |
90 | ``` bash
91 | IP 地址 已发送 已接收 丢包率 平均延迟 下载速度 (MB/s)
92 | 104.27.200.69 4 4 0.00 146.23 28.64
93 | 172.67.60.78 4 4 0.00 139.82 15.02
94 | 104.25.140.153 4 4 0.00 146.49 14.90
95 | 104.27.192.65 4 4 0.00 140.28 14.07
96 | 172.67.62.214 4 4 0.00 139.29 12.71
97 | 104.27.207.5 4 4 0.00 145.92 11.95
98 | 172.67.54.193 4 4 0.00 146.71 11.55
99 | 104.22.66.8 4 4 0.00 147.42 11.11
100 | 104.27.197.63 4 4 0.00 131.29 10.26
101 | 172.67.58.91 4 4 0.00 140.19 9.14
102 | ...
103 |
104 | # 如果平均延迟非常低(如 0.xx),则说明 CloudflareST 测速时走了代理,请先关闭代理软件后再测速。
105 | # 如果在路由器上运行,请先关闭路由器内的代理(或将其排除),否则测速结果可能会不准确/无法使用。
106 |
107 | # 因为每次测速都是在每个 IP 段中随机 IP,所以每次的测速结果都不可能相同,这是正常的!
108 |
109 | # 注意!我发现电脑开机后第一次测速延迟会明显偏高(手动 TCPing 也一样),后续测速都正常
110 | # 因此建议大家开机后第一次正式测速前,先随便测几个 IP(无需等待延迟测速完成,只要进度条动了就可以直接关了)
111 |
112 | # 软件在 默认参数 下的整个流程大概步骤:
113 | # 1. 延迟测速(默认 TCPing 模式,HTTPing 模式需要手动加上参数)
114 | # 2. 延迟排序(延迟从低到高排序,不同丢包率的会分开独立排序,因此可能会有一些延迟低但丢包的 IP 被排到后面)
115 | # 3. 下载测速(从延迟最低的 IP 开始依次下载测速,默认测够 10 个就会停止)
116 | # 4. 速度排序(速度从高到低排序)
117 | # 5. 输出结果(可依靠参数控制是否输出到命令行(-p 0)/文件(-o ""))
118 | ```
119 |
120 | 测速结果第一行就是**既下载速度最快、又平均延迟最低的最快 IP**!至于拿来干嘛?取决于你~
121 |
122 | 完整结果保存在当前目录下的 `result.csv` 文件中,用**记事本/表格软件**打开,格式如下:
123 |
124 | ```
125 | IP 地址, 已发送, 已接收, 丢包率, 平均延迟, 下载速度 (MB/s)
126 | 104.27.200.69,4,4,0.00,146.23,28.64
127 | ```
128 |
129 | > _大家可以按自己需求,对完整结果**进一步筛选处理**,或者去看一看进阶使用**指定过滤条件**!_
130 |
131 | ****
132 | ## \# 进阶使用
133 |
134 | 直接运行使用的是默认参数,如果想要测速结果更全面、更符合自己的要求,可以自定义参数。
135 |
136 | ``` cmd
137 | C:\>CloudflareST.exe -h
138 |
139 | CloudflareSpeedTest vX.X.X
140 | 测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP (IPv4+IPv6)!
141 | https://github.com/XIU2/CloudflareSpeedTest
142 |
143 | 参数:
144 | -n 200
145 | 延迟测速线程;越多延迟测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000)
146 | -t 4
147 | 延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP;(默认 4 次)
148 | -dn 10
149 | 下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10 个)
150 | -dt 10
151 | 下载测速时间;单个 IP 下载测速最长时间,不能太短;(默认 10 秒)
152 | -tp 443
153 | 指定测速端口;延迟测速/下载测速时使用的端口;(默认 443 端口)
154 | -url https://cf.xiu2.xyz/url
155 | 指定测速地址;延迟测速(HTTPing)/下载测速时使用的地址,默认地址不保证可用性,建议自建;
156 |
157 | -httping
158 | 切换测速模式;延迟测速模式改为 HTTP 协议,所用测试地址为 [-url] 参数;(默认 TCPing)
159 | 注意:HTTPing 本质上也算一种 网络扫描 行为,因此如果你在服务器上面运行,需要降低并发(-n),否则可能会被一些严格的商家暂停服务。
160 | 如果你遇到 HTTPing 首次测速可用 IP 数量正常,后续测速越来越少甚至直接为 0,但停一段时间后又恢复了的情况,那么也可能是被 运营商、Cloudflare CDN 认为你在网络扫描而 触发临时限制机制,因此才会过一会儿就恢复了,建议降低并发(-n)减少这种情况的发生。
161 | -httping-code 200
162 | 有效状态代码;HTTPing 延迟测速时网页返回的有效 HTTP 状态码,仅限一个;(默认 200 301 302)
163 | -cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD
164 | 匹配指定地区;地区名为当地机场三字码,英文逗号分隔,仅 HTTPing 模式可用;(默认 所有地区)
165 |
166 | -tl 200
167 | 平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms)
168 | -tll 40
169 | 平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 0 ms)
170 | -sl 5
171 | 下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
172 |
173 | -p 10
174 | 显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 10 个)
175 | -f ip.txt
176 | IP段数据文件;如路径含有空格请加上引号;支持其他 CDN IP段;(默认 ip.txt)
177 | -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32
178 | 指定IP段数据;直接通过参数指定要测速的 IP 段数据,英文逗号分隔;(默认 空)
179 | -o result.csv
180 | 写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
181 |
182 | -dd
183 | 禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
184 | -allip
185 | 测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 /24 段随机测速一个 IP)
186 |
187 | -v
188 | 打印程序版本 + 检查版本更新
189 | -h
190 | 打印帮助说明
191 | ```
192 |
193 | ### 使用示例
194 |
195 | Windows 要指定参数需要在 CMD 中运行,或者把参数添加到快捷方式目标中。
196 |
197 | > **注意**:各参数均有**默认值**,使用默认值的参数是可以省略的(**按需选择**),参数**不分前后顺序**。
198 | > **提示**:Windows **PowerShell** 只需把下面命令中的 `CloudflareST.exe` 改为 `.\CloudflareST.exe` 即可。
199 | > **提示**:Linux 系统只需要把下面命令中的 `CloudflareST.exe` 改为 `./CloudflareST` 即可。
200 |
201 | ****
202 |
203 | #### \# CMD 带参数运行 CloudflareST
204 |
205 | 对命令行程序不熟悉的人,可能不知道该如何带参数运行,我就简单说一下。
206 |
207 |
208 | 「 点击展开 查看内容 」
209 |
210 | ****
211 |
212 | 很多人打开 CMD 以**绝对路径**运行 CloudflareST 会报错,这是因为默认的 `-f ip.txt` 参数是相对路径,需要指定绝对路径的 ip.txt 才行,但这样毕竟太麻烦了,因此还是建议进入 CloudflareST 程序目录下,以**相对路径**方式运行:
213 |
214 | **方式 一**:
215 | 1. 打开 CloudflareST 程序所在目录
216 | 2. 空白处按下 Shift + 鼠标右键 显示右键菜单
217 | 3. 选择 **\[在此处打开命令窗口\]** 来打开 CMD 窗口,此时默认就位于当前目录下
218 | 4. 输入带参数的命令,如:`CloudflareST.exe -tll 50 -tl 200`即可运行
219 |
220 | **方式 二**:
221 | 1. 打开 CloudflareST 程序所在目录
222 | 2. 直接在文件夹地址栏中全选并输入 `cmd` 回车来打开 CMD 窗口,此时默认就位于当前目录下
223 | 4. 输入带参数的命令,如:`CloudflareST.exe -tll 50 -tl 200`即可运行
224 |
225 | > 当然你也可以随便打开一个 CMD 窗口,然后输入如 `cd /d "D:\Program Files\CloudflareST"` 来进入程序目录
226 |
227 | > **提示**:如果用的是 **PowerShell** 只需把命令中的 `CloudflareST.exe` 改为 `.\CloudflareST.exe` 即可。
228 |
229 |
230 |
231 | ****
232 |
233 | #### \# Windows 快捷方式带参数运行 CloudflareST
234 |
235 | 如果不经常修改运行参数(比如平时都是直接双击运行)的人,建议使用快捷方式,更方便点。
236 |
237 |
238 | 「 点击展开 查看内容 」
239 |
240 | ****
241 |
242 | 右键 `CloudflareST.exe` 文件 - **\[创建快捷方式\]**,然后右键该快捷方式 - **\[属性\]**,修改其**目标**:
243 |
244 | ``` bash
245 | # 如果要不输出结果文件,那么请加上 -o " ",引号里的是空格(没有空格会导致该参数被省略)。
246 | D:\ABC\CloudflareST\CloudflareST.exe -n 500 -t 4 -dn 20 -dt 5 -o " "
247 |
248 | # 如果文件路径包含引号,则需要把启动参数放在引号外面,记得引号和 - 之间有空格。
249 | "D:\Program Files\CloudflareST\CloudflareST.exe" -n 500 -t 4 -dn 20 -dt 5 -o " "
250 |
251 | # 注意!快捷方式 - 起始位置 不能是空的,否则就会因为绝对路径而找不到 ip.txt 文件
252 | ```
253 |
254 |
255 |
256 | ****
257 |
258 | #### \# IPv4/IPv6
259 |
260 |
261 | 「 点击展开 查看内容 」
262 |
263 | ****
264 | ``` bash
265 | # 测速 IPv4 时,需要指定 IPv4 数据文件(-f 默认值就是 ip.txt,所以该参数可省略)
266 | CloudflareST.exe -f ip.txt
267 |
268 | # 测速 IPv6 时,需要指定 IPv6 数据文件(v2.1.0 版本后支持 IPv4+IPv6 混合测速并移除了 -ipv6 参数)
269 | CloudflareST.exe -f ipv6.txt
270 |
271 | # 当然你也可以将 IPv4 IPv6 混合在一起测速,也可以直接通过参数指定要测速的 IP
272 | CloudflareST.exe -ip 1.1.1.1,2606:4700::/32
273 | ```
274 |
275 | > 测速 IPv6 时,可能会注意到每次测速数量都不一样,了解原因: [#120](https://github.com/XIU2/CloudflareSpeedTest/issues/120)
276 | > 因为 IPv6 太多(以亿为单位),且绝大部分 IP 段压根未启用,所以我只扫了一部分可用的 IPv6 段写到 `ipv6.txt` 文件中,有兴趣的可以自行扫描增删,ASN 数据源来自:[bgp.he.net](https://bgp.he.net/AS13335#_prefixes6)
277 |
278 |
279 |
280 | ****
281 |
282 | #### \# HTTPing
283 |
284 |
285 | 「 点击展开 查看内容 」
286 |
287 | ****
288 |
289 | 目前有两种延迟测速模式,分别为 **TCP 协议、HTTP 协议**。
290 | TCP 协议耗时更短、消耗资源更少,超时时间为 1 秒,该协议为默认模式。
291 | HTTP 协议适用于快速测试某域名指向某 IP 时是否可以访问,超时时间为 2 秒。
292 | 同一个 IP,各协议去 Ping 得到的延迟一般为:**ICMP < TCP < HTTP**,越靠右对丢包等网络波动越敏感。
293 |
294 | > 注意:HTTPing 本质上也算一种**网络扫描**行为,因此如果你在服务器上面运行,需要**降低并发**(`-n`),否则可能会被一些严格的商家暂停服务。如果你遇到 HTTPing 首次测速可用 IP 数量正常,后续测速越来越少甚至直接为 0,但停一段时间后又恢复了的情况,那么也可能是被 运营商、Cloudflare CDN 认为你在网络扫描而**触发临时限制机制**,因此才会过一会儿就恢复了,建议**降低并发**(`-n`)减少这种情况的发生。
295 |
296 | ``` bash
297 | # 只需加上 -httping 参数即可切换到 HTTP 协议延迟测速模式
298 | CloudflareST.exe -httping
299 |
300 | # 软件会根据访问时网页返回的有效 HTTP 状态码来判断可用性(当然超时也算),默认对返回 200 301 302 这三个 HTTP 状态码的视为有效,可以手动指定认为有效的 HTTP 状态码,但只能指定一个(你需要提前确定测试地址正常情况下会返回哪个状态码)
301 | CloudflareST.exe -httping -httping-code 200
302 |
303 | # 通过 -url 参数来指定 HTTPing 测试地址(可以是任意网页 URL,不局限于具体文件地址)
304 | CloudflareST.exe -httping -url https://cf.xiu2.xyz/url
305 |
306 | # 注意:如果测速地址为 HTTP 协议,记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口)
307 | # 同理,如果要测速 80 端口,那么也需要加上 -url 参数来指定一个 http:// 协议的地址才行(且该地址不会强制重定向至 HTTPS),如果是非 80 443 端口,那么需要确定该下载测速地址是否支持通过该端口访问。
308 | CloudflareST.exe -httping -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
309 | ```
310 |
311 |
312 |
313 | ****
314 |
315 | #### \# 匹配指定地区(colo 机场三字码)
316 |
317 |
318 | 「 点击展开 查看内容 」
319 |
320 | ****
321 |
322 | ``` bash
323 | # 指定地区名后,延迟测速后得到的结果就都是指定地区的 IP 了(也可以继续进行下载测速)
324 | # 节点地区名为当地 机场三字码,指定多个时用英文逗号分隔
325 |
326 | CloudflareST.exe -cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD
327 |
328 | # 注意,该参数只有在 HTTPing 延迟测速模式下才可用(因为要访问网页来获得)
329 | ```
330 |
331 | > Cloudflare 所有节点地区名(机场三字码),请看:https://www.cloudflarestatus.com/
332 |
333 |
334 |
335 | ****
336 |
337 | #### \# 文件相对/绝对路径
338 |
339 |
340 | 「 点击展开 查看内容 」
341 |
342 | ****
343 |
344 | ``` bash
345 | # 指定 IPv4 数据文件,不显示结果直接退出,输出结果到文件(-p 值为 0)
346 | CloudflareST.exe -f 1.txt -p 0 -dd
347 |
348 | # 指定 IPv4 数据文件,不输出结果到文件,直接显示结果(-p 值为 10 条,-o 值为空但引号不能少)
349 | CloudflareST.exe -f 2.txt -o "" -p 10 -dd
350 |
351 | # 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录下,如含空格请加上引号)
352 | CloudflareST.exe -f 3.txt -o result.txt -dd
353 |
354 |
355 | # 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录内的 abc 文件夹下,如含空格请加上引号)
356 | # Linux(CloudflareST 程序所在目录内的 abc 文件夹下)
357 | ./CloudflareST -f abc/3.txt -o abc/result.txt -dd
358 |
359 | # Windows(注意是反斜杠)
360 | CloudflareST.exe -f abc\3.txt -o abc\result.txt -dd
361 |
362 |
363 | # 指定 IPv4 数据文件 及 输出结果到文件(绝对路径,即 C:\abc\ 目录下,如含空格请加上引号)
364 | # Linux(/abc/ 目录下)
365 | ./CloudflareST -f /abc/4.txt -o /abc/result.csv -dd
366 |
367 | # Windows(注意是反斜杠)
368 | CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
369 |
370 |
371 | # 如果要以【绝对路径】运行 CloudflareST,那么 -f / -o 参数中的文件名也必须是【绝对路径】,否则会报错找不到文件!
372 | # Linux(/abc/ 目录下)
373 | /abc/CloudflareST -f /abc/4.txt -o /abc/result.csv -dd
374 |
375 | # Windows(注意是反斜杠)
376 | C:\abc\CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
377 | ```
378 |
379 |
380 | ****
381 |
382 | #### \# 测速其他端口
383 |
384 |
385 | 「 点击展开 查看内容 」
386 |
387 | ****
388 |
389 | ``` bash
390 | # 如果你想要测速非默认 443 的其他端口,则需要通过 -tp 参数指定(该参数会影响 延迟测速/下载测速 时使用的端口)
391 |
392 | # 如果要延迟测速 80 端口+下载测速(如果 -dd 禁用了下载测速则不需要),那么还需要指定 http:// 协议的下载测速地址才行(且该地址不会强制重定向至 HTTPS,因为那样就变成 443 端口了)
393 | CloudflareST.exe -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
394 |
395 | # 如果是非 80 443 的其他端口,那么需要确定你使用的下载测速地址是否支持通过该非标端口访问。
396 | ```
397 |
398 |
399 |
400 | ****
401 |
402 | #### \# 自定义测速地址
403 |
404 |
405 | 「 点击展开 查看内容 」
406 |
407 | ****
408 |
409 | ``` bash
410 | # 该参数适用于下载测速 及 HTTP 协议的延迟测速,对于后者该地址可以是任意网页 URL(不局限于具体文件地址)
411 |
412 | # 地址要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN
413 | CloudflareST.exe -url https://cf.xiu2.xyz/url
414 |
415 | # 注意:如果测速地址为 HTTP 协议(该地址不能强制重定向至 HTTPS),记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口),如果是非 80 443 端口,那么需要确定下载测速地址是否支持通过该端口访问。
416 | CloudflareST.exe -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
417 | ```
418 |
419 |
420 |
421 | ****
422 |
423 | #### \# 自定义测速条件(指定 延迟/下载速度 的目标范围)
424 |
425 |
426 | 「 点击展开 查看内容 」
427 |
428 | ****
429 |
430 | > 注意:延迟测速进度条右边的**可用数量**,仅指延迟测速过程中**未超时的 IP 数量**,和延迟上下限条件无关。
431 |
432 | - 指定 **[平均延迟下限]** 条件
433 |
434 | ``` bash
435 | # 平均延迟下限:40 ms (一般除了移动直连香港外,几乎不存在低于 100ms 的,自行测试适合的下限延迟)
436 | # 平均延迟下限和其他的上下限参数一样,都可以单独使用、互相搭配使用!
437 | CloudflareST.exe -tll 40
438 | ```
439 |
440 | - 仅指定 **[平均延迟上限]** 条件
441 |
442 | ``` bash
443 | # 平均延迟上限:200 ms,下载速度下限:0 MB/s,数量:10 个(可选)
444 | # 即找到平均延迟低于 200 ms 的 IP,然后再按延迟从低到高进行 10 次下载测速
445 | CloudflareST.exe -tl 200 -dn 10
446 | ```
447 |
448 | > 如果**没有找到一个满足延迟**条件的 IP,那么不会输出任何内容。
449 |
450 | ****
451 |
452 | - 仅指定 **[平均延迟上限]** 条件,且**只延迟测速,不下载测速**
453 |
454 | ``` bash
455 | # 平均延迟上限:200 ms,下载速度下限:0 MB/s,数量:不知道多少 个
456 | # 即只输出低于 200ms 的 IP,且不再下载测速(因为不再下载测速,所以 -dn 参数就无效了)
457 | CloudflareST.exe -tl 200 -dd
458 | ```
459 |
460 | ****
461 |
462 | - 仅指定 **[下载速度下限]** 条件
463 |
464 | ``` bash
465 | # 平均延迟上限:9999 ms,下载速度下限:5 MB/s,数量:10 个(可选)
466 | # 即需要找到 10 个平均延迟低于 9999 ms 且下载速度高于 5 MB/s 的 IP 才会停止测速
467 | CloudflareST.exe -sl 5 -dn 10
468 | ```
469 |
470 | > 如果**没有找到一个满足速度**条件的 IP,那么会**忽略条件输出所有 IP 测速结果**(方便你下次测速时调整条件)。
471 |
472 | > 没有指定平均延迟上限时,如果一直**凑不够**满足条件的 IP 数量,就会**一直测速**下去。
473 | > 所以建议**同时指定 [下载速度下限] + [平均延迟上限]**,这样测速到指定延迟上限还没凑够数量,就会终止测速。
474 |
475 | ****
476 |
477 | - 同时指定 **[平均延迟上限] + [下载速度下限]** 条件
478 |
479 | ``` bash
480 | # 平均延迟上限、下载速度下限均支持小数(如 -sl 0.5)
481 | # 平均延迟上限:200 ms,下载速度下限:5.6 MB/s,数量:10 个(可选)
482 | # 即需要找到 10 个平均延迟低于 200 ms 且下载速度高于 5 .6MB/s 的 IP 才会停止测速
483 | CloudflareST.exe -tl 200 -sl 5.6 -dn 10
484 | ```
485 |
486 | > 如果**没有找到一个满足延迟**条件的 IP,那么不会输出任何内容。
487 | > 如果**没有找到一个满足速度**条件的 IP,那么会忽略条件输出所有 IP 测速结果(方便你下次测速时调整条件)。
488 | > 所以建议先不指定条件测速一遍,看看平均延迟和下载速度大概在什么范围,避免指定条件**过低/过高**!
489 |
490 | > 因为Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法使用的,所以下载测速是 0.00。
491 | > 运行时可以加上 `-sl 0.01`(下载速度下限),过滤掉**回源 IP**(下载测速低于 0.01MB/s 的结果)。
492 |
493 |
494 |
495 | ****
496 |
497 | #### \# 单独对一个或多个 IP 测速
498 |
499 |
500 | 「 点击展开 查看内容 」
501 |
502 | ****
503 |
504 | **方式 一**:
505 | 直接通过参数指定要测速的 IP 段数据。
506 | ``` bash
507 | # 先进入 CloudflareST 所在目录,然后运行:
508 | # Windows 系统(在 CMD 中运行)
509 | CloudflareST.exe -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32
510 |
511 | # Linux 系统
512 | ./CloudflareST -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32
513 | ```
514 |
515 | ****
516 |
517 | **方式 二**:
518 | 或者把这些 IP 按如下格式写入到任意文本文件中,例如:`1.txt`
519 |
520 | ```
521 | 1.1.1.1
522 | 1.1.1.200
523 | 1.0.0.1/24
524 | 2606:4700::/32
525 | ```
526 |
527 | > 单个 IP 的话可以省略 `/32` 子网掩码了(即 `1.1.1.1`等同于 `1.1.1.1/32`)。
528 | > 子网掩码 `/24` 指的是这个 IP 最后一段,即 `1.0.0.1~1.0.0.255`。
529 |
530 |
531 | 然后运行 CloudflareST 时加上启动参数 `-f 1.txt` 来指定 IP 段数据文件。
532 |
533 | ``` bash
534 | # 先进入 CloudflareST 所在目录,然后运行:
535 | # Windows 系统(在 CMD 中运行)
536 | CloudflareST.exe -f 1.txt
537 |
538 | # Linux 系统
539 | ./CloudflareST -f 1.txt
540 |
541 | # 对于 1.0.0.1/24 这样的 IP 段只会随机最后一段(1.0.0.1~255),如果要测速该 IP 段中的所有 IP,请加上 -allip 参数。
542 | ```
543 |
544 |
545 |
546 | ****
547 |
--------------------------------------------------------------------------------
/READMEs.md:
--------------------------------------------------------------------------------
1 | # XIU2/CloudflareSpeedTest
2 | [](https://github.com/XIU2/CloudflareSpeedTest/)
3 | [](https://github.com/XIU2/CloudflareSpeedTest/releases/latest)
4 | [](https://github.com/XIU2/CloudflareSpeedTest/)
5 | [](https://github.com/XIU2/CloudflareSpeedTest/)
6 | [](https://github.com/XIU2/CloudflareSpeedTest/)
7 |
8 | 国外很多网站都在使用 Cloudflare CDN,但分配给中国内地访客的 IP 并不友好(延迟高、丢包多、速度慢)。
9 | 虽然 Cloudflare 公开了所有 [IP 段](https://www.cloudflare.com/ips/) ,但想要在这么多 IP 中找到适合自己的,怕是要累死,于是就有了这个软件。
10 |
11 | **「自选优选 IP」测试 Cloudflare CDN 延迟和速度,获取最快 IP (IPv4+IPv6)**!好用的话**点个`⭐`鼓励一下叭~**
12 |
13 | > _分享我其他开源项目:[**TrackersList.com** - 全网热门 BT Tracker 列表!有效提高 BT 下载速度~](https://github.com/XIU2/TrackersListCollection)
_
14 | > _[**UserScript** - 🐵 Github 高速下载、知乎增强、自动无缝翻页、护眼模式 等十几个**油猴脚本**!](https://github.com/XIU2/UserScript)
_
15 |
16 | > 本项目也支持对**其他 CDN / 网站 IP** 延迟测速(如:[CloudFront](https://github.com/XIU2/CloudflareSpeedTest/discussions/304)、[Gcore](https://github.com/XIU2/CloudflareSpeedTest/discussions/303) CDN),但下载测速需自行寻找地址
17 |
18 | > 对于**代理套 Cloudflare CDN** 的用户,须知这应为**备用方案**,而不应该是**唯一方案**,请勿过度依赖 [#217](https://github.com/XIU2/CloudflareSpeedTest/issues/217) [#188](https://github.com/XIU2/CloudflareSpeedTest/issues/188)
19 |
20 | ****
21 | ## \# 快速使用
22 |
23 | ### 下载运行
24 |
25 | 1. 下载编译好的可执行文件 [蓝奏云](https://pan.lanzouf.com/b0742hkxe) / [Github](https://github.com/XIU2/CloudflareSpeedTest/releases) 并解压。
26 | 2. 双击运行 `CloudflareST.exe` 文件(Windows 系统),等待测速完成...
27 |
28 |
29 | 「 点击查看 Linux 系统下的使用示例 」
30 |
31 | ****
32 |
33 | 以下命令仅为示例,版本号和文件名请前往 [**Releases**](https://github.com/XIU2/CloudflareSpeedTest/releases) 查看。
34 |
35 | ``` yaml
36 | # 如果是第一次使用,则建议创建新文件夹(后续更新时,跳过该步骤)
37 | mkdir CloudflareST
38 |
39 | # 进入文件夹(后续更新,只需要从这里重复下面的下载、解压命令即可)
40 | cd CloudflareST
41 |
42 | # 下载 CloudflareST 压缩包(自行根据需求替换 URL 中 [版本号] 和 [文件名])
43 | wget -N https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.2.2/CloudflareST_linux_amd64.tar.gz
44 | # 如果你是在国内服务器上下载,那么请使用下面这几个镜像加速:
45 | # wget -N https://download.fastgit.org/XIU2/CloudflareSpeedTest/releases/download/v2.2.2/CloudflareST_linux_amd64.tar.gz
46 | # wget -N https://ghproxy.com/https://github.com/XIU2/CloudflareSpeedTest/releases/download/v2.2.2/CloudflareST_linux_amd64.tar.gz
47 | # 如果下载失败的话,尝试删除 -N 参数(如果是为了更新,则记得提前删除旧压缩包 rm CloudflareST_linux_amd64.tar.gz )
48 |
49 | # 解压(不需要删除旧文件,会直接覆盖,自行根据需求替换 文件名)
50 | tar -zxf CloudflareST_linux_amd64.tar.gz
51 |
52 | # 赋予执行权限
53 | chmod +x CloudflareST
54 |
55 | # 运行(不带参数)
56 | ./CloudflareST
57 |
58 | # 运行(带参数示例)
59 | ./CloudflareST -dd -tll 90
60 | ```
61 |
62 | > 如果平**均延迟非常低**(如 0.xx),则说明 CloudflareST **测速时走了代理**,请先关闭代理软件后再测速。
63 | > 如果在**路由器**上运行,建议先关闭路由器内的代理(或将其排除),否则测速结果可能会**不准确/无法使用**。
64 |
65 |
66 |
67 | ****
68 |
69 | > _在**手机**上独立运行 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)**_
70 |
71 | ### 结果示例
72 |
73 | 测速完毕后,默认会显示**最快的 10 个 IP**,示例:
74 |
75 | ``` bash
76 | IP 地址 已发送 已接收 丢包率 平均延迟 下载速度 (MB/s)
77 | 104.27.200.69 4 4 0.00 146.23 28.64
78 | 172.67.60.78 4 4 0.00 139.82 15.02
79 | 104.25.140.153 4 4 0.00 146.49 14.90
80 | 104.27.192.65 4 4 0.00 140.28 14.07
81 | 172.67.62.214 4 4 0.00 139.29 12.71
82 | 104.27.207.5 4 4 0.00 145.92 11.95
83 | 172.67.54.193 4 4 0.00 146.71 11.55
84 | 104.22.66.8 4 4 0.00 147.42 11.11
85 | 104.27.197.63 4 4 0.00 131.29 10.26
86 | 172.67.58.91 4 4 0.00 140.19 9.14
87 | ...
88 |
89 | # 如果平均延迟非常低(如 0.xx),则说明 CloudflareST 测速时走了代理,请先关闭代理软件后再测速。
90 | # 如果在路由器上运行,请先关闭路由器内的代理(或将其排除),否则测速结果可能会不准确/无法使用。
91 |
92 | # 因为每次测速都是在每个 IP 段中随机 IP,所以每次的测速结果都不可能相同,这是正常的!
93 |
94 | # 注意!我发现电脑开机后第一次测速延迟会明显偏高(手动 TCPing 也一样),后续测速都正常
95 | # 因此建议大家开机后第一次正式测速前,先随便测几个 IP(无需等待延迟测速完成,只要进度条动了就可以直接关了)
96 |
97 | # 软件在 默认参数 下的整个流程大概步骤:
98 | # 1. 延迟测速(默认 TCPing 模式,HTTPing 模式需要手动加上参数)
99 | # 2. 延迟排序(延迟从低到高排序,不同丢包率的会分开独立排序,因此可能会有一些延迟低但丢包的 IP 被排到后面)
100 | # 3. 下载测速(从延迟最低的 IP 开始依次下载测速,默认测够 10 个就会停止)
101 | # 4. 速度排序(速度从高到低排序)
102 | # 5. 输出结果(可依靠参数控制是否输出到命令行(-p 0)/文件(-o ""))
103 | ```
104 |
105 | 测速结果第一行就是**既下载速度最快、又平均延迟最低的最快 IP**!至于拿来干嘛?取决于你~
106 |
107 | 完整结果保存在当前目录下的 `result.csv` 文件中,用**记事本/表格软件**打开,格式如下:
108 |
109 | ```
110 | IP 地址, 已发送, 已接收, 丢包率, 平均延迟, 下载速度 (MB/s)
111 | 104.27.200.69,4,4,0.00,146.23,28.64
112 | ```
113 |
114 | > _大家可以按自己需求,对完整结果**进一步筛选处理**,或者去看一看进阶使用**指定过滤条件**!_
115 |
116 | ****
117 | ## \# 进阶使用
118 |
119 | 直接运行使用的是默认参数,如果想要测速结果更全面、更符合自己的要求,可以自定义参数。
120 |
121 | ``` cmd
122 | C:\>CloudflareST.exe -h
123 |
124 | CloudflareSpeedTest vX.X.X
125 | 测试 Cloudflare CDN 所有 IP 的延迟和速度,获取最快 IP (IPv4+IPv6)!
126 | https://github.com/XIU2/CloudflareSpeedTest
127 |
128 | 参数:
129 | -n 200
130 | 延迟测速线程;越多延迟测速越快,性能弱的设备 (如路由器) 请勿太高;(默认 200 最多 1000)
131 | -t 4
132 | 延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP;(默认 4 次)
133 | -dn 10
134 | 下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10 个)
135 | -dt 10
136 | 下载测速时间;单个 IP 下载测速最长时间,不能太短;(默认 10 秒)
137 | -tp 443
138 | 指定测速端口;延迟测速/下载测速时使用的端口;(默认 443 端口)
139 | -url https://cf.xiu2.xyz/url
140 | 指定测速地址;延迟测速(HTTPing)/下载测速时使用的地址,默认地址不保证可用性,建议自建;
141 |
142 | -httping
143 | 切换测速模式;延迟测速模式改为 HTTP 协议,所用测试地址为 [-url] 参数;(默认 TCPing)
144 | 注意:HTTPing 本质上也算一种 网络扫描 行为,因此如果你在服务器上面运行,需要降低并发(-n),否则可能会被一些严格的商家暂停服务。
145 | 如果你遇到 HTTPing 首次测速可用 IP 数量正常,后续测速越来越少甚至直接为 0,但停一段时间后又恢复了的情况,那么也可能是被 运营商、Cloudflare CDN 认为你在网络扫描而 触发临时限制机制,因此才会过一会儿就恢复了,建议降低并发(-n)减少这种情况的发生。
146 | -httping-code 200
147 | 有效状态代码;HTTPing 延迟测速时网页返回的有效 HTTP 状态码,仅限一个;(默认 200 301 302)
148 | -cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD
149 | 匹配指定地区;地区名为当地机场三字码,英文逗号分隔,仅 HTTPing 模式可用;(默认 所有地区)
150 |
151 | -tl 200
152 | 平均延迟上限;只输出低于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 9999 ms)
153 | -tll 40
154 | 平均延迟下限;只输出高于指定平均延迟的 IP,可与其他上限/下限搭配;(默认 0 ms)
155 | -sl 5
156 | 下载速度下限;只输出高于指定下载速度的 IP,凑够指定数量 [-dn] 才会停止测速;(默认 0.00 MB/s)
157 |
158 | -p 10
159 | 显示结果数量;测速后直接显示指定数量的结果,为 0 时不显示结果直接退出;(默认 10 个)
160 | -f ip.txt
161 | IP段数据文件;如路径含有空格请加上引号;支持其他 CDN IP段;(默认 ip.txt)
162 | -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32
163 | 指定IP段数据;直接通过参数指定要测速的 IP 段数据,英文逗号分隔;(默认 空)
164 | -o result.csv
165 | 写入结果文件;如路径含有空格请加上引号;值为空时不写入文件 [-o ""];(默认 result.csv)
166 |
167 | -dd
168 | 禁用下载测速;禁用后测速结果会按延迟排序 (默认按下载速度排序);(默认 启用)
169 | -allip
170 | 测速全部的IP;对 IP 段中的每个 IP (仅支持 IPv4) 进行测速;(默认 每个 /24 段随机测速一个 IP)
171 |
172 | -v
173 | 打印程序版本 + 检查版本更新
174 | -h
175 | 打印帮助说明
176 | ```
177 |
178 | ### 使用示例
179 |
180 | Windows 要指定参数需要在 CMD 中运行,或者把参数添加到快捷方式目标中。
181 |
182 | > **注意**:各参数均有**默认值**,使用默认值的参数是可以省略的(**按需选择**),参数**不分前后顺序**。
183 | > **提示**:Windows **PowerShell** 只需把下面命令中的 `CloudflareST.exe` 改为 `.\CloudflareST.exe` 即可。
184 | > **提示**:Linux 系统只需要把下面命令中的 `CloudflareST.exe` 改为 `./CloudflareST` 即可。
185 |
186 | ****
187 |
188 | #### \# CMD 带参数运行 CloudflareST
189 |
190 | 对命令行程序不熟悉的人,可能不知道该如何带参数运行,我就简单说一下。
191 |
192 |
193 | 「 点击展开 查看内容 」
194 |
195 | ****
196 |
197 | 很多人打开 CMD 以**绝对路径**运行 CloudflareST 会报错,这是因为默认的 `-f ip.txt` 参数是相对路径,需要指定绝对路径的 ip.txt 才行,但这样毕竟太麻烦了,因此还是建议进入 CloudflareST 程序目录下,以**相对路径**方式运行:
198 |
199 | **方式 一**:
200 | 1. 打开 CloudflareST 程序所在目录
201 | 2. 空白处按下 Shift + 鼠标右键 显示右键菜单
202 | 3. 选择 **\[在此处打开命令窗口\]** 来打开 CMD 窗口,此时默认就位于当前目录下
203 | 4. 输入带参数的命令,如:`CloudflareST.exe -tll 50 -tl 200`即可运行
204 |
205 | **方式 二**:
206 | 1. 打开 CloudflareST 程序所在目录
207 | 2. 直接在文件夹地址栏中全选并输入 `cmd` 回车来打开 CMD 窗口,此时默认就位于当前目录下
208 | 4. 输入带参数的命令,如:`CloudflareST.exe -tll 50 -tl 200`即可运行
209 |
210 | > 当然你也可以随便打开一个 CMD 窗口,然后输入如 `cd /d "D:\Program Files\CloudflareST"` 来进入程序目录
211 |
212 | > **提示**:如果用的是 **PowerShell** 只需把命令中的 `CloudflareST.exe` 改为 `.\CloudflareST.exe` 即可。
213 |
214 |
215 |
216 | ****
217 |
218 | #### \# Windows 快捷方式带参数运行 CloudflareST
219 |
220 | 如果不经常修改运行参数(比如平时都是直接双击运行)的人,建议使用快捷方式,更方便点。
221 |
222 |
223 | 「 点击展开 查看内容 」
224 |
225 | ****
226 |
227 | 右键 `CloudflareST.exe` 文件 - **\[创建快捷方式\]**,然后右键该快捷方式 - **\[属性\]**,修改其**目标**:
228 |
229 | ``` bash
230 | # 如果要不输出结果文件,那么请加上 -o " ",引号里的是空格(没有空格会导致该参数被省略)。
231 | D:\ABC\CloudflareST\CloudflareST.exe -n 500 -t 4 -dn 20 -dt 5 -o " "
232 |
233 | # 如果文件路径包含引号,则需要把启动参数放在引号外面,记得引号和 - 之间有空格。
234 | "D:\Program Files\CloudflareST\CloudflareST.exe" -n 500 -t 4 -dn 20 -dt 5 -o " "
235 |
236 | # 注意!快捷方式 - 起始位置 不能是空的,否则就会因为绝对路径而找不到 ip.txt 文件
237 | ```
238 |
239 |
240 |
241 | ****
242 |
243 | #### \# IPv4/IPv6
244 |
245 |
246 | 「 点击展开 查看内容 」
247 |
248 | ****
249 | ``` bash
250 | # 测速 IPv4 时,需要指定 IPv4 数据文件(-f 默认值就是 ip.txt,所以该参数可省略)
251 | CloudflareST.exe -f ip.txt
252 |
253 | # 测速 IPv6 时,需要指定 IPv6 数据文件(v2.1.0 版本后支持 IPv4+IPv6 混合测速并移除了 -ipv6 参数)
254 | CloudflareST.exe -f ipv6.txt
255 |
256 | # 当然你也可以将 IPv4 IPv6 混合在一起测速,也可以直接通过参数指定要测速的 IP
257 | CloudflareST.exe -ip 1.1.1.1,2606:4700::/32
258 | ```
259 |
260 | > 测速 IPv6 时,可能会注意到每次测速数量都不一样,了解原因: [#120](https://github.com/XIU2/CloudflareSpeedTest/issues/120)
261 | > 因为 IPv6 太多(以亿为单位),且绝大部分 IP 段压根未启用,所以我只扫了一部分可用的 IPv6 段写到 `ipv6.txt` 文件中,有兴趣的可以自行扫描增删,ASN 数据源来自:[bgp.he.net](https://bgp.he.net/AS13335#_prefixes6)
262 |
263 |
264 |
265 | ****
266 |
267 | #### \# HTTPing
268 |
269 |
270 | 「 点击展开 查看内容 」
271 |
272 | ****
273 |
274 | 目前有两种延迟测速模式,分别为 **TCP 协议、HTTP 协议**。
275 | TCP 协议耗时更短、消耗资源更少,超时时间为 1 秒,该协议为默认模式。
276 | HTTP 协议适用于快速测试某域名指向某 IP 时是否可以访问,超时时间为 2 秒。
277 | 同一个 IP,各协议去 Ping 得到的延迟一般为:**ICMP < TCP < HTTP**,越靠右对丢包等网络波动越敏感。
278 |
279 | > 注意:HTTPing 本质上也算一种**网络扫描**行为,因此如果你在服务器上面运行,需要**降低并发**(`-n`),否则可能会被一些严格的商家暂停服务。如果你遇到 HTTPing 首次测速可用 IP 数量正常,后续测速越来越少甚至直接为 0,但停一段时间后又恢复了的情况,那么也可能是被 运营商、Cloudflare CDN 认为你在网络扫描而**触发临时限制机制**,因此才会过一会儿就恢复了,建议**降低并发**(`-n`)减少这种情况的发生。
280 |
281 | ``` bash
282 | # 只需加上 -httping 参数即可切换到 HTTP 协议延迟测速模式
283 | CloudflareST.exe -httping
284 |
285 | # 软件会根据访问时网页返回的有效 HTTP 状态码来判断可用性(当然超时也算),默认对返回 200 301 302 这三个 HTTP 状态码的视为有效,可以手动指定认为有效的 HTTP 状态码,但只能指定一个(你需要提前确定测试地址正常情况下会返回哪个状态码)
286 | CloudflareST.exe -httping -httping-code 200
287 |
288 | # 通过 -url 参数来指定 HTTPing 测试地址(可以是任意网页 URL,不局限于具体文件地址)
289 | CloudflareST.exe -httping -url https://cf.xiu2.xyz/url
290 |
291 | # 注意:如果测速地址为 HTTP 协议,记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口)
292 | # 同理,如果要测速 80 端口,那么也需要加上 -url 参数来指定一个 http:// 协议的地址才行(且该地址不会强制重定向至 HTTPS),如果是非 80 443 端口,那么需要确定该下载测速地址是否支持通过该端口访问。
293 | CloudflareST.exe -httping -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
294 | ```
295 |
296 |
297 |
298 | ****
299 |
300 | #### \# 匹配指定地区(colo 机场三字码)
301 |
302 |
303 | 「 点击展开 查看内容 」
304 |
305 | ****
306 |
307 | ``` bash
308 | # 指定地区名后,延迟测速后得到的结果就都是指定地区的 IP 了(也可以继续进行下载测速)
309 | # 节点地区名为当地 机场三字码,指定多个时用英文逗号分隔
310 |
311 | CloudflareST.exe -cfcolo HKG,KHH,NRT,LAX,SEA,SJC,FRA,MAD
312 |
313 | # 注意,该参数只有在 HTTPing 延迟测速模式下才可用(因为要访问网页来获得)
314 | ```
315 |
316 | > Cloudflare 所有节点地区名(机场三字码),请看:https://www.cloudflarestatus.com/
317 |
318 |
319 |
320 | ****
321 |
322 | #### \# 文件相对/绝对路径
323 |
324 |
325 | 「 点击展开 查看内容 」
326 |
327 | ****
328 |
329 | ``` bash
330 | # 指定 IPv4 数据文件,不显示结果直接退出,输出结果到文件(-p 值为 0)
331 | CloudflareST.exe -f 1.txt -p 0 -dd
332 |
333 | # 指定 IPv4 数据文件,不输出结果到文件,直接显示结果(-p 值为 10 条,-o 值为空但引号不能少)
334 | CloudflareST.exe -f 2.txt -o "" -p 10 -dd
335 |
336 | # 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录下,如含空格请加上引号)
337 | CloudflareST.exe -f 3.txt -o result.txt -dd
338 |
339 |
340 | # 指定 IPv4 数据文件 及 输出结果到文件(相对路径,即当前目录内的 abc 文件夹下,如含空格请加上引号)
341 | # Linux(CloudflareST 程序所在目录内的 abc 文件夹下)
342 | ./CloudflareST -f abc/3.txt -o abc/result.txt -dd
343 |
344 | # Windows(注意是反斜杠)
345 | CloudflareST.exe -f abc\3.txt -o abc\result.txt -dd
346 |
347 |
348 | # 指定 IPv4 数据文件 及 输出结果到文件(绝对路径,即 C:\abc\ 目录下,如含空格请加上引号)
349 | # Linux(/abc/ 目录下)
350 | ./CloudflareST -f /abc/4.txt -o /abc/result.csv -dd
351 |
352 | # Windows(注意是反斜杠)
353 | CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
354 |
355 |
356 | # 如果要以【绝对路径】运行 CloudflareST,那么 -f / -o 参数中的文件名也必须是【绝对路径】,否则会报错找不到文件!
357 | # Linux(/abc/ 目录下)
358 | /abc/CloudflareST -f /abc/4.txt -o /abc/result.csv -dd
359 |
360 | # Windows(注意是反斜杠)
361 | C:\abc\CloudflareST.exe -f C:\abc\4.txt -o C:\abc\result.csv -dd
362 | ```
363 |
364 |
365 | ****
366 |
367 | #### \# 测速其他端口
368 |
369 |
370 | 「 点击展开 查看内容 」
371 |
372 | ****
373 |
374 | ``` bash
375 | # 如果你想要测速非默认 443 的其他端口,则需要通过 -tp 参数指定(该参数会影响 延迟测速/下载测速 时使用的端口)
376 |
377 | # 如果要延迟测速 80 端口+下载测速(如果 -dd 禁用了下载测速则不需要),那么还需要指定 http:// 协议的下载测速地址才行(且该地址不会强制重定向至 HTTPS,因为那样就变成 443 端口了)
378 | CloudflareST.exe -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
379 |
380 | # 如果是非 80 443 的其他端口,那么需要确定你使用的下载测速地址是否支持通过该非标端口访问。
381 | ```
382 |
383 |
384 |
385 | ****
386 |
387 | #### \# 自定义测速地址
388 |
389 |
390 | 「 点击展开 查看内容 」
391 |
392 | ****
393 |
394 | ``` bash
395 | # 该参数适用于下载测速 及 HTTP 协议的延迟测速,对于后者该地址可以是任意网页 URL(不局限于具体文件地址)
396 |
397 | # 地址要求:可以直接下载、文件大小超过 200MB、用的是 Cloudflare CDN
398 | CloudflareST.exe -url https://cf.xiu2.xyz/url
399 |
400 | # 注意:如果测速地址为 HTTP 协议(该地址不能强制重定向至 HTTPS),记得加上 -tp 80(这个参数会影响 延迟测速/下载测速 时使用的端口),如果是非 80 443 端口,那么需要确定下载测速地址是否支持通过该端口访问。
401 | CloudflareST.exe -tp 80 -url http://cdn.cloudflare.steamstatic.com/steam/apps/5952/movie_max.webm
402 | ```
403 |
404 |
405 |
406 | ****
407 |
408 | #### \# 自定义测速条件(指定 延迟/下载速度 的目标范围)
409 |
410 |
411 | 「 点击展开 查看内容 」
412 |
413 | ****
414 |
415 | > 注意:延迟测速进度条右边的**可用数量**,仅指延迟测速过程中**未超时的 IP 数量**,和延迟上下限条件无关。
416 |
417 | - 指定 **[平均延迟下限]** 条件
418 |
419 | ``` bash
420 | # 平均延迟下限:40 ms (一般除了移动直连香港外,几乎不存在低于 100ms 的,自行测试适合的下限延迟)
421 | # 平均延迟下限和其他的上下限参数一样,都可以单独使用、互相搭配使用!
422 | CloudflareST.exe -tll 40
423 | ```
424 |
425 | - 仅指定 **[平均延迟上限]** 条件
426 |
427 | ``` bash
428 | # 平均延迟上限:200 ms,下载速度下限:0 MB/s,数量:10 个(可选)
429 | # 即找到平均延迟低于 200 ms 的 IP,然后再按延迟从低到高进行 10 次下载测速
430 | CloudflareST.exe -tl 200 -dn 10
431 | ```
432 |
433 | > 如果**没有找到一个满足延迟**条件的 IP,那么不会输出任何内容。
434 |
435 | ****
436 |
437 | - 仅指定 **[平均延迟上限]** 条件,且**只延迟测速,不下载测速**
438 |
439 | ``` bash
440 | # 平均延迟上限:200 ms,下载速度下限:0 MB/s,数量:不知道多少 个
441 | # 即只输出低于 200ms 的 IP,且不再下载测速(因为不再下载测速,所以 -dn 参数就无效了)
442 | CloudflareST.exe -tl 200 -dd
443 | ```
444 |
445 | ****
446 |
447 | - 仅指定 **[下载速度下限]** 条件
448 |
449 | ``` bash
450 | # 平均延迟上限:9999 ms,下载速度下限:5 MB/s,数量:10 个(可选)
451 | # 即需要找到 10 个平均延迟低于 9999 ms 且下载速度高于 5 MB/s 的 IP 才会停止测速
452 | CloudflareST.exe -sl 5 -dn 10
453 | ```
454 |
455 | > 如果**没有找到一个满足速度**条件的 IP,那么会**忽略条件输出所有 IP 测速结果**(方便你下次测速时调整条件)。
456 |
457 | > 没有指定平均延迟上限时,如果一直**凑不够**满足条件的 IP 数量,就会**一直测速**下去。
458 | > 所以建议**同时指定 [下载速度下限] + [平均延迟上限]**,这样测速到指定延迟上限还没凑够数量,就会终止测速。
459 |
460 | ****
461 |
462 | - 同时指定 **[平均延迟上限] + [下载速度下限]** 条件
463 |
464 | ``` bash
465 | # 平均延迟上限、下载速度下限均支持小数(如 -sl 0.5)
466 | # 平均延迟上限:200 ms,下载速度下限:5.6 MB/s,数量:10 个(可选)
467 | # 即需要找到 10 个平均延迟低于 200 ms 且下载速度高于 5 .6MB/s 的 IP 才会停止测速
468 | CloudflareST.exe -tl 200 -sl 5.6 -dn 10
469 | ```
470 |
471 | > 如果**没有找到一个满足延迟**条件的 IP,那么不会输出任何内容。
472 | > 如果**没有找到一个满足速度**条件的 IP,那么会忽略条件输出所有 IP 测速结果(方便你下次测速时调整条件)。
473 | > 所以建议先不指定条件测速一遍,看看平均延迟和下载速度大概在什么范围,避免指定条件**过低/过高**!
474 |
475 | > 因为Cloudflare 公开的 IP 段是**回源 IP+任播 IP**,而**回源 IP**是无法使用的,所以下载测速是 0.00。
476 | > 运行时可以加上 `-sl 0.01`(下载速度下限),过滤掉**回源 IP**(下载测速低于 0.01MB/s 的结果)。
477 |
478 |
479 |
480 | ****
481 |
482 | #### \# 单独对一个或多个 IP 测速
483 |
484 |
485 | 「 点击展开 查看内容 」
486 |
487 | ****
488 |
489 | **方式 一**:
490 | 直接通过参数指定要测速的 IP 段数据。
491 | ``` bash
492 | # 先进入 CloudflareST 所在目录,然后运行:
493 | # Windows 系统(在 CMD 中运行)
494 | CloudflareST.exe -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32
495 |
496 | # Linux 系统
497 | ./CloudflareST -ip 1.1.1.1,2.2.2.2/24,2606:4700::/32
498 | ```
499 |
500 | ****
501 |
502 | **方式 二**:
503 | 或者把这些 IP 按如下格式写入到任意文本文件中,例如:`1.txt`
504 |
505 | ```
506 | 1.1.1.1
507 | 1.1.1.200
508 | 1.0.0.1/24
509 | 2606:4700::/32
510 | ```
511 |
512 | > 单个 IP 的话可以省略 `/32` 子网掩码了(即 `1.1.1.1`等同于 `1.1.1.1/32`)。
513 | > 子网掩码 `/24` 指的是这个 IP 最后一段,即 `1.0.0.1~1.0.0.255`。
514 |
515 |
516 | 然后运行 CloudflareST 时加上启动参数 `-f 1.txt` 来指定 IP 段数据文件。
517 |
518 | ``` bash
519 | # 先进入 CloudflareST 所在目录,然后运行:
520 | # Windows 系统(在 CMD 中运行)
521 | CloudflareST.exe -f 1.txt
522 |
523 | # Linux 系统
524 | ./CloudflareST -f 1.txt
525 |
526 | # 对于 1.0.0.1/24 这样的 IP 段只会随机最后一段(1.0.0.1~255),如果要测速该 IP 段中的所有 IP,请加上 -allip 参数。
527 | ```
528 |
529 |
530 |
531 | ****
532 |
533 | #### \# 一劳永逸加速所有使用 Cloudflare CDN 的网站(不需要再一个个添加域名到 Hosts 了)
534 |
535 | 我以前说过,开发该软件项目的目的就是为了通过**改 Hosts 的方式来加速访问使用 Cloudflare CDN 的网站**。
536 |
537 | 但就如 [**#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) 的教程。
538 |
539 | ****
540 |
541 | #### \# 自动更新 Hosts
542 |
543 | 考虑到很多人获得最快 Cloudflare CDN IP 后,需要替换 Hosts 文件中的 IP。
544 |
545 | 可以看这个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/discussions/312) 获取 **Windows/Linux 自动更新 Hosts 脚本**!
546 |
547 | ****
548 |
549 | ## 问题反馈
550 |
551 | 如果你遇到什么问题,可以先去 [**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) 的)。
552 | 如果没找到类似问题,请新开个 [**Issues**](https://github.com/XIU2/CloudflareSpeedTest/issues/new) 来告诉我!
553 |
554 | > **注意**!_与 `反馈问题、功能建议` 无关的,请前往项目内部 论坛 讨论(上面的 `💬 Discussions`_
555 |
556 | ****
557 |
558 | ## 赞赏支持
559 |
560 | 
561 |
562 | ****
563 |
564 | ## 衍生项目
565 |
566 | - _https://github.com/xianshenglu/cloudflare-ip-tester-app_
567 | _**CloudflareST 安卓版 APP [#202](https://github.com/XIU2/CloudflareSpeedTest/discussions/320)**_
568 |
569 | - _https://github.com/mingxiaoyu/luci-app-cloudflarespeedtest_
570 | _**CloudflareST OpenWrt 路由器插件版 [#174](https://github.com/XIU2/CloudflareSpeedTest/discussions/319)**_
571 |
572 | - _https://github.com/immortalwrt-collections/openwrt-cdnspeedtest_
573 | _**CloudflareST OpenWrt 原生编译版本 [#64](https://github.com/XIU2/CloudflareSpeedTest/discussions/64)**_
574 |
575 | - _https://github.com/hoseinnikkhah/CloudflareSpeedTest-English_
576 | _**English language version of CloudflareST (Text language differences only) [#64](https://github.com/XIU2/CloudflareSpeedTest/issues/68)**_
577 |
578 | > _此处仅收集了在本项目中宣传过的部分 CloudflareST 相关衍生项目,如果有遗漏可以告诉我~_
579 |
580 | ****
581 |
582 | ## 感谢项目
583 |
584 | - _https://github.com/Spedoske/CloudflareScanner_
585 |
586 | > _因为该项目已经很长时间没更新了,而我又产生了很多功能需求,所以我临时学了下 Go 语言就上手了(菜)..._
587 | > _本软件基于该项目制作,但**已添加大量功能及修复 BUG**,并根据大家的使用反馈积极添加、优化功能(闲)..._
588 |
589 | ****
590 |
591 | ## 手动编译
592 |
593 |
594 | 「 点击展开 查看内容 」
595 |
596 | ****
597 |
598 | 为了方便,我是在编译的时候将版本号写入代码中的 version 变量,因此你手动编译时,需要像下面这样在 `go build` 命令后面加上 `-ldflags` 参数来指定版本号:
599 |
600 | ```bash
601 | go build -ldflags "-s -w -X main.version=v2.3.3"
602 | # 在 CloudflareSpeedTest 目录中通过命令行(例如 CMD、Bat 脚本)运行该命令,即可编译一个可在和当前设备同样系统、位数、架构的环境下运行的二进制程序(Go 会自动检测你的系统位数、架构)且版本号为 v2.3.3
603 | ```
604 |
605 | 如果想要在 Windows 64位系统下编译**其他系统、架构、位数**,那么需要指定 **GOOS** 和 **GOARCH** 变量。
606 |
607 | 例如在 Windows 系统下编译一个适用于 **Linux 系统 amd 架构 64 位**的二进制程序:
608 |
609 | ```bat
610 | SET GOOS=linux
611 | SET GOARCH=amd64
612 | go build -ldflags "-s -w -X main.version=v2.3.3"
613 | ```
614 |
615 | 例如在 Linux 系统下编译一个适用于 **Windows 系统 amd 架构 32 位**的二进制程序:
616 |
617 | ```bash
618 | GOOS=windows
619 | GOARCH=386
620 | go build -ldflags "-s -w -X main.version=v2.3.3"
621 | ```
622 |
623 | > 可以运行 `go tool dist list` 来查看当前 Go 版本支持编译哪些组合。
624 |
625 | ****
626 |
627 | 当然,为了方便批量编译,我会专门指定一个变量为版本号,后续编译直接调用该版本号变量即可。
628 | 同时,批量编译的话,还需要分开放到不同文件夹才行(或者文件名不同),需要加上 `-o` 参数指定。
629 |
630 | ```bat
631 | :: Windows 系统下是这样:
632 | SET version=v2.3.3
633 | SET GOOS=linux
634 | SET GOARCH=amd64
635 | go build -o Releases\CloudflareST_linux_amd64\CloudflareST -ldflags "-s -w -X main.version=%version%"
636 | ```
637 |
638 | ```bash
639 | # Linux 系统下是这样:
640 | version=v2.3.3
641 | GOOS=windows
642 | GOARCH=386
643 | go build -o Releases/CloudflareST_windows_386/CloudflareST.exe -ldflags "-s -w -X main.version=${version}"
644 | ```
645 |
646 |
647 |
648 | ****
649 |
650 | ## License
651 |
652 | The GPL-3.0 License.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------