mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-04-14 01:25:27 +08:00
新增 下载测速也会使用 -tp 参数指定的端口; 调整 下载测速进度条数字
This commit is contained in:
@@ -115,7 +115,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
-t 4
|
-t 4
|
||||||
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
||||||
-tp 443
|
-tp 443
|
||||||
延迟测速端口;延迟测速 TCP 协议的端口;(默认 443)
|
指定测速端口;延迟测速/下载测速时使用的端口;(默认 443)
|
||||||
-dn 10
|
-dn 10
|
||||||
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10)
|
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10)
|
||||||
-dt 10
|
-dt 10
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -30,7 +30,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
-t 4
|
-t 4
|
||||||
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
延迟测速次数;单个 IP 延迟测速次数,为 1 时将过滤丢包的IP,TCP协议;(默认 4)
|
||||||
-tp 443
|
-tp 443
|
||||||
延迟测速端口;延迟测速 TCP 协议的端口;(默认 443)
|
指定测速端口;延迟测速/下载测速时使用的端口;(默认 443)
|
||||||
-dn 10
|
-dn 10
|
||||||
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10)
|
下载测速数量;延迟测速并排序后,从最低延迟起下载测速的数量;(默认 10)
|
||||||
-dt 10
|
-dt 10
|
||||||
@@ -63,7 +63,7 @@ https://github.com/XIU2/CloudflareSpeedTest
|
|||||||
var minDelay, maxDelay, downloadTime int
|
var minDelay, maxDelay, downloadTime int
|
||||||
flag.IntVar(&task.Routines, "n", 200, "测速线程数量")
|
flag.IntVar(&task.Routines, "n", 200, "测速线程数量")
|
||||||
flag.IntVar(&task.PingTimes, "t", 4, "延迟测速次数")
|
flag.IntVar(&task.PingTimes, "t", 4, "延迟测速次数")
|
||||||
flag.IntVar(&task.TCPPort, "tp", 443, "延迟测速端口")
|
flag.IntVar(&task.TCPPort, "tp", 443, "指定测速端口")
|
||||||
flag.IntVar(&maxDelay, "tl", 9999, "平均延迟上限")
|
flag.IntVar(&maxDelay, "tl", 9999, "平均延迟上限")
|
||||||
flag.IntVar(&minDelay, "tll", 0, "平均延迟下限")
|
flag.IntVar(&minDelay, "tll", 0, "平均延迟下限")
|
||||||
flag.IntVar(&downloadTime, "dt", 10, "下载测速时间")
|
flag.IntVar(&downloadTime, "dt", 10, "下载测速时间")
|
||||||
@@ -134,7 +134,7 @@ func endPrint() {
|
|||||||
func checkUpdate() {
|
func checkUpdate() {
|
||||||
timeout := 10 * time.Second
|
timeout := 10 * time.Second
|
||||||
client := http.Client{Timeout: timeout}
|
client := http.Client{Timeout: timeout}
|
||||||
res, err := client.Get("https://api.xiuer.pw/ver/cloudflarespeedtest.txt")
|
res, err := client.Get("https://api.xiu2.xyz/ver/cloudflarespeedtest.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSe
|
|||||||
if len(ipSet) < TestCount || MinSpeed > 0 { // 如果IP数组长度(IP数量) 小于下载测速数量(-dn),则次数修正为IP数
|
if len(ipSet) < TestCount || MinSpeed > 0 { // 如果IP数组长度(IP数量) 小于下载测速数量(-dn),则次数修正为IP数
|
||||||
testNum = len(ipSet)
|
testNum = len(ipSet)
|
||||||
}
|
}
|
||||||
|
if testNum < TestCount {
|
||||||
|
TestCount = testNum
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s,下载测速数量:%d,下载测速队列:%d):\n", MinSpeed, TestCount, testNum)
|
fmt.Printf("开始下载测速(下载速度下限:%.2f MB/s,下载测速数量:%d,下载测速队列:%d):\n", MinSpeed, TestCount, testNum)
|
||||||
bar := utils.NewBar(TestCount)
|
bar := utils.NewBar(TestCount)
|
||||||
@@ -88,9 +91,9 @@ func TestDownloadSpeed(ipSet utils.PingDelaySet) (speedSet utils.DownloadSpeedSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getDialContext(ip *net.IPAddr) func(ctx context.Context, network, address string) (net.Conn, error) {
|
func getDialContext(ip *net.IPAddr) func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
fakeSourceAddr := ip.String() + ":443"
|
fakeSourceAddr := ip.String() + ":" + fmt.Sprintf("%d", TCPPort)
|
||||||
if IPv6 { // IPv6 需要加上 []
|
if IPv6 { // IPv6 需要加上 []
|
||||||
fakeSourceAddr = "[" + ip.String() + "]:443"
|
fakeSourceAddr = "[" + ip.String() + "]:" + fmt.Sprintf("%d", TCPPort)
|
||||||
}
|
}
|
||||||
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
return func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
return (&net.Dialer{}).DialContext(ctx, network, fakeSourceAddr)
|
return (&net.Dialer{}).DialContext(ctx, network, fakeSourceAddr)
|
||||||
|
|||||||
Reference in New Issue
Block a user