Skip to content

Commit e9680e9

Browse files
committed
update
1 parent 02dc41a commit e9680e9

5 files changed

Lines changed: 135 additions & 25 deletions

File tree

go.mod

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,33 @@ module github.com/oneclickvirt/pingtest
33
go 1.22.4
44

55
require (
6+
github.com/imroc/req/v3 v3.43.7
67
github.com/oneclickvirt/defaultset v0.0.2-20240624082446
78
github.com/prometheus-community/pro-bing v0.4.0
89
)
910

1011
require (
12+
github.com/andybalholm/brotli v1.1.0 // indirect
13+
github.com/cloudflare/circl v1.3.7 // indirect
14+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
15+
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 // indirect
1116
github.com/google/uuid v1.6.0 // indirect
17+
github.com/hashicorp/errwrap v1.1.0 // indirect
18+
github.com/hashicorp/go-multierror v1.1.1 // indirect
19+
github.com/klauspost/compress v1.17.7 // indirect
20+
github.com/onsi/ginkgo/v2 v2.16.0 // indirect
21+
github.com/quic-go/qpack v0.4.0 // indirect
22+
github.com/quic-go/quic-go v0.41.0 // indirect
23+
github.com/refraction-networking/utls v1.6.3 // indirect
24+
go.uber.org/mock v0.4.0 // indirect
1225
go.uber.org/multierr v1.10.0 // indirect
1326
go.uber.org/zap v1.27.0 // indirect
14-
golang.org/x/net v0.21.0 // indirect
27+
golang.org/x/crypto v0.21.0 // indirect
28+
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
29+
golang.org/x/mod v0.16.0 // indirect
30+
golang.org/x/net v0.22.0 // indirect
1531
golang.org/x/sync v0.6.0 // indirect
16-
golang.org/x/sys v0.17.0 // indirect
32+
golang.org/x/sys v0.18.0 // indirect
33+
golang.org/x/text v0.14.0 // indirect
34+
golang.org/x/tools v0.19.0 // indirect
1735
)

go.sum

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,78 @@
1+
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
2+
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
3+
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
4+
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
5+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
16
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
27
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
9+
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
10+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
11+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
12+
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
13+
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
14+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
15+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
16+
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7 h1:y3N7Bm7Y9/CtpiVkw/ZWj6lSlDF3F74SfKwfTCer72Q=
17+
github.com/google/pprof v0.0.0-20240227163752-401108e1b7e7/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
318
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
419
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
20+
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
21+
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
22+
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
23+
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
24+
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
25+
github.com/imroc/req/v3 v3.43.7 h1:dOcNb9n0X83N5/5/AOkiU+cLhzx8QFXjv5MhikazzQA=
26+
github.com/imroc/req/v3 v3.43.7/go.mod h1:SQIz5iYop16MJxbo8ib+4LnostGCok8NQf8ToyQc2xA=
27+
github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg=
28+
github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
529
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
630
github.com/oneclickvirt/defaultset v0.0.2-20240624082446/go.mod h1:e9Jt4tf2sbemCtc84/XgKcHy9EZ2jkc5x2sW1NiJS+E=
31+
github.com/onsi/ginkgo/v2 v2.16.0 h1:7q1w9frJDzninhXxjZd+Y/x54XNjG/UlRLIYPZafsPM=
32+
github.com/onsi/ginkgo/v2 v2.16.0/go.mod h1:llBI3WDLL9Z6taip6f33H76YcWtJv+7R3HigUjbIBOs=
33+
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
34+
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
735
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
836
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
937
github.com/prometheus-community/pro-bing v0.4.0 h1:YMbv+i08gQz97OZZBwLyvmmQEEzyfyrrjEaAchdy3R4=
1038
github.com/prometheus-community/pro-bing v0.4.0/go.mod h1:b7wRYZtCcPmt4Sz319BykUU241rWLe1VFXyiyWK/dH4=
39+
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
40+
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
41+
github.com/quic-go/quic-go v0.41.0 h1:aD8MmHfgqTURWNJy48IYFg2OnxwHT3JL7ahGs73lb4k=
42+
github.com/quic-go/quic-go v0.41.0/go.mod h1:qCkNjqczPEvgsOnxZ0eCD14lv+B2LHlFAB++CNOh9hA=
43+
github.com/refraction-networking/utls v1.6.3 h1:MFOfRN35sSx6K5AZNIoESsBuBxS2LCgRilRIdHb6fDc=
44+
github.com/refraction-networking/utls v1.6.3/go.mod h1:yil9+7qSl+gBwJqztoQseO6Pr3h62pQoY1lXiNR/FPs=
45+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
46+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1147
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
1248
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
1349
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
1450
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
51+
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
52+
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
1553
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
1654
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
1755
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
1856
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
19-
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
20-
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
57+
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
58+
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
59+
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
60+
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
61+
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
62+
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
63+
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
64+
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
2165
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
2266
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
23-
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
24-
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
67+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
68+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
69+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
70+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
71+
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
72+
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
73+
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
74+
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
75+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
76+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2577
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2678
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

model/model.go

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,12 @@ const PingTestVersion = "v0.0.1"
55
var EnableLoger = false
66

77
var (
8-
NetCMCC = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Mobile.csv"
9-
NetCT = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Telecom.csv"
10-
NetCU = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Unicom.csv"
11-
NetHK = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/HK.csv"
12-
NetJP = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/JP.csv"
13-
NetTW = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/TW.csv"
14-
NetSG = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/SG.csv"
15-
NetGlobal = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/ls_sg_hk_jp.csv"
16-
17-
CnCMCC = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/mobile.csv"
18-
CnCT = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/telecom.csv"
19-
CnCU = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/unicom.csv"
20-
CnHK = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/HK.csv"
21-
CnJP = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/JP.csv"
22-
CnTW = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/TW.csv"
23-
CnSG = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/SG.csv"
24-
8+
NetCMCC = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Mobile.csv"
9+
NetCT = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Telecom.csv"
10+
NetCU = "https://raw.githubusercontent.com/spiritLHLS/speedtest.net-CN-ID/main/CN_Unicom.csv"
11+
CnCMCC = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/mobile.csv"
12+
CnCT = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/telecom.csv"
13+
CnCU = "https://raw.githubusercontent.com/spiritLHLS/speedtest.cn-CN-ID/main/unicom.csv"
2514
CdnList = []string{
2615
"http://cdn0.spiritlhl.top/",
2716
"http://cdn1.spiritlhl.top/",
@@ -30,3 +19,10 @@ var (
3019
"http://cdn2.spiritlhl.net/",
3120
}
3221
)
22+
23+
type Server struct {
24+
Name string
25+
IP string
26+
Port string
27+
Avg int
28+
}

pt/pt.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,24 @@ func PingTest() string {
3737
pinger.SetPrivileged(true)
3838
}
3939
// 开始ping操作
40-
err = pinger.Run() // 阻塞,直到ping操作完成
40+
err = pinger.Run() // 阻塞
4141
if err != nil {
4242
if model.EnableLoger {
4343
Logger.Info("ping failed: " + err.Error())
4444
}
45+
pinger.SetPrivileged(true) // 无特权模式操作失败,切换特权模式
46+
err = pinger.Run() // 阻塞
47+
if err != nil {
48+
if model.EnableLoger {
49+
Logger.Info("ping failed: " + err.Error())
50+
}
51+
}
4552
}
4653
// 获取ping统计信息
4754
stats := pinger.Statistics()
4855
// 打印ping统计信息
4956
result += fmt.Sprintf("\n--- %s ping statistics ---\n", stats.Addr)
50-
result += fmt.Sprintf("%d packets transmitted, %d packets received, %v% packet loss\n",
57+
result += fmt.Sprintf("%d packets transmitted, %d packets received, %v%% packet loss\n",
5158
stats.PacketsSent, stats.PacketsRecv, stats.PacketLoss)
5259
result += fmt.Sprintf("round-trip min/avg/max/stddev = %v/%v/%v/%v\n",
5360
stats.MinRtt, stats.AvgRtt, stats.MaxRtt, stats.StdDevRtt)

pt/utils.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package pt
2+
3+
import (
4+
"time"
5+
6+
"github.com/imroc/req/v3"
7+
. "github.com/oneclickvirt/defaultset"
8+
"github.com/oneclickvirt/pingtest/model"
9+
)
10+
11+
func getData(endpoint string) string {
12+
client := req.C()
13+
client.SetTimeout(6 * time.Second)
14+
client.R().
15+
SetRetryCount(2).
16+
SetRetryBackoffInterval(1*time.Second, 5*time.Second).
17+
SetRetryFixedInterval(2 * time.Second)
18+
if model.EnableLoger {
19+
InitLogger()
20+
defer Logger.Sync()
21+
}
22+
for _, baseUrl := range model.CdnList {
23+
url := baseUrl + endpoint
24+
resp, err := client.R().Get(url)
25+
if err == nil {
26+
defer resp.Body.Close()
27+
b, err := io.ReadAll(resp.Body)
28+
if err == nil {
29+
return string(b)
30+
}
31+
}
32+
if model.EnableLoger {
33+
Logger.Info(err.Error())
34+
}
35+
}
36+
return ""
37+
}

0 commit comments

Comments
 (0)