mirror of
https://github.com/XIU2/CloudflareSpeedTest.git
synced 2026-03-21 06:50:18 +08:00
rebuild tcping
This commit is contained in:
24
utils/csv.go
24
utils/csv.go
@@ -9,19 +9,23 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type PingData struct {
|
||||
IP net.IPAddr
|
||||
Count int
|
||||
Received int
|
||||
Delay time.Duration
|
||||
}
|
||||
|
||||
type CloudflareIPData struct {
|
||||
ip net.IPAddr
|
||||
pingCount int
|
||||
pingReceived int
|
||||
*PingData
|
||||
recvRate float32
|
||||
downloadSpeed float32
|
||||
pingTime time.Duration
|
||||
}
|
||||
|
||||
func (cf *CloudflareIPData) getRecvRate() float32 {
|
||||
if cf.recvRate == 0 {
|
||||
pingLost := cf.pingCount - cf.pingReceived
|
||||
cf.recvRate = float32(pingLost) / float32(cf.pingCount)
|
||||
pingLost := cf.Count - cf.Received
|
||||
cf.recvRate = float32(pingLost) / float32(cf.Count)
|
||||
}
|
||||
return cf.recvRate
|
||||
}
|
||||
@@ -41,11 +45,11 @@ func ExportCsv(filePath string, data []CloudflareIPData) {
|
||||
|
||||
func (cf *CloudflareIPData) toString() []string {
|
||||
result := make([]string, 6)
|
||||
result[0] = cf.ip.String()
|
||||
result[1] = strconv.Itoa(cf.pingCount)
|
||||
result[2] = strconv.Itoa(cf.pingReceived)
|
||||
result[0] = cf.IP.String()
|
||||
result[1] = strconv.Itoa(cf.Count)
|
||||
result[2] = strconv.Itoa(cf.Received)
|
||||
result[3] = strconv.FormatFloat(float64(cf.getRecvRate()), 'f', 2, 32)
|
||||
result[4] = cf.pingTime.String()
|
||||
result[4] = cf.Delay.String()
|
||||
result[5] = strconv.FormatFloat(float64(cf.downloadSpeed)/1024/1024, 'f', 2, 32)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package utils
|
||||
|
||||
import "github.com/cheggaaa/pb/v3"
|
||||
|
||||
type ProgressEvent int
|
||||
|
||||
const (
|
||||
@@ -7,3 +9,24 @@ const (
|
||||
AvailableIPFound
|
||||
NormalPing
|
||||
)
|
||||
|
||||
type Bar struct {
|
||||
*pb.ProgressBar
|
||||
}
|
||||
|
||||
func NewBar(count int) *Bar {
|
||||
return &Bar{pb.Simple.Start(count)}
|
||||
}
|
||||
|
||||
func handleProgressGenerator(pb *pb.ProgressBar) func(e ProgressEvent) {
|
||||
return func(e ProgressEvent) {
|
||||
switch e {
|
||||
case NoAvailableIPFound:
|
||||
// pb.Add(pingTime)
|
||||
case AvailableIPFound:
|
||||
// pb.Add(failTime)
|
||||
case NormalPing:
|
||||
pb.Increment()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user