v1.2.1
This commit is contained in:
parent
479629b84e
commit
31743a8138
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
||||||
module CloudflareIPScanner
|
module CloudflareSpeedTest
|
||||||
|
|
||||||
go 1.14
|
go 1.14
|
||||||
|
|
||||||
|
|
40
main.go
40
main.go
|
@ -61,6 +61,21 @@ https://github.com/XIU2/CloudflareSpeedTest
|
||||||
println(version)
|
println(version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
if pingRoutine <= 0 {
|
||||||
|
pingRoutine = 500
|
||||||
|
}
|
||||||
|
if pingTime <= 0 {
|
||||||
|
pingTime = 4
|
||||||
|
}
|
||||||
|
if downloadTestCount <= 0 {
|
||||||
|
downloadTestCount = 20
|
||||||
|
}
|
||||||
|
if downloadSecond <= 0 {
|
||||||
|
downloadSecond = 10
|
||||||
|
}
|
||||||
|
if ipFile == "" {
|
||||||
|
ipFile = "ip.txt"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -74,12 +89,11 @@ func main() {
|
||||||
var data = make([]CloudflareIPData, 0)
|
var data = make([]CloudflareIPData, 0)
|
||||||
|
|
||||||
fmt.Println("开始延迟测速(TCP):")
|
fmt.Println("开始延迟测速(TCP):")
|
||||||
|
|
||||||
control := make(chan bool, pingRoutine)
|
control := make(chan bool, pingRoutine)
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
control <- false
|
control <- false
|
||||||
handleProgress := handleProgressGenerator(bar)
|
handleProgress := handleProgressGenerator(bar) // 多线程进度条
|
||||||
go tcpingGoroutine(&wg, &mu, ip, pingTime, &data, control, handleProgress)
|
go tcpingGoroutine(&wg, &mu, ip, pingTime, &data, control, handleProgress)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -87,14 +101,22 @@ func main() {
|
||||||
|
|
||||||
sort.Sort(CloudflareIPDataSet(data)) // 排序
|
sort.Sort(CloudflareIPDataSet(data)) // 排序
|
||||||
if !disableDownload { // 如果禁用下载测速就跳过
|
if !disableDownload { // 如果禁用下载测速就跳过
|
||||||
bar = pb.Simple.Start(downloadTestCount)
|
if len(data) > 0 { // IP数组长度(IP数量) 大于 0 时继续
|
||||||
fmt.Println("开始下载测速:")
|
if len(data) < downloadTestCount { // 如果IP数组长度(IP数量) 小于 下载测速次数,则次数改为IP数
|
||||||
for i := 0; i < downloadTestCount; i++ {
|
downloadTestCount = len(data)
|
||||||
_, speed := DownloadSpeedHandler(data[i].ip)
|
fmt.Println("\n[信息] IP数量小于下载测速次数,下载测速次数改为IP数。\n")
|
||||||
data[i].downloadSpeed = speed
|
}
|
||||||
bar.Add(1)
|
bar = pb.Simple.Start(downloadTestCount)
|
||||||
|
fmt.Println("开始下载测速:")
|
||||||
|
for i := 0; i < downloadTestCount; i++ {
|
||||||
|
_, speed := DownloadSpeedHandler(data[i].ip)
|
||||||
|
data[i].downloadSpeed = speed
|
||||||
|
bar.Add(1)
|
||||||
|
}
|
||||||
|
bar.Finish()
|
||||||
|
} else {
|
||||||
|
fmt.Println("\n[信息] IP数量为 0,跳过下载测速。")
|
||||||
}
|
}
|
||||||
bar.Finish()
|
|
||||||
}
|
}
|
||||||
ExportCsv("./result.csv", data) // 输出结果
|
ExportCsv("./result.csv", data) // 输出结果
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,14 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/VividCortex/ewma"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/VividCortex/ewma"
|
||||||
)
|
)
|
||||||
|
|
||||||
//bool connectionSucceed float32 time
|
//bool connectionSucceed float32 time
|
||||||
|
@ -130,7 +131,7 @@ func DownloadSpeedHandler(ip net.IPAddr) (bool, float32) {
|
||||||
var nextTime = timeStart.Add(timeSlice * time.Duration(timeCounter))
|
var nextTime = timeStart.Add(timeSlice * time.Duration(timeCounter))
|
||||||
e := ewma.NewMovingAverage()
|
e := ewma.NewMovingAverage()
|
||||||
|
|
||||||
for ; contentLength != contentRead; {
|
for contentLength != contentRead {
|
||||||
var currentTime = time.Now()
|
var currentTime = time.Now()
|
||||||
if currentTime.After(nextTime) {
|
if currentTime.After(nextTime) {
|
||||||
timeCounter += 1
|
timeCounter += 1
|
||||||
|
|
Loading…
Reference in New Issue