Added a general network test command using speedtest.net API
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
33
cmd/net.go
Normal file
33
cmd/net.go
Normal file
@ -0,0 +1,33 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/showwin/speedtest-go/speedtest"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var netCmd = &cobra.Command{
|
||||
Use: "net",
|
||||
Short: "Network test using SpeedTest.net.",
|
||||
Long: "A network test that utilizes the SpeedTest.net API to determine network bandwidth and latency.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
user, _ := speedtest.FetchUserInfo()
|
||||
|
||||
serverList, _ := speedtest.FetchServers(user)
|
||||
targets, _ := serverList.FindServer([]int{})
|
||||
|
||||
for _, s := range targets {
|
||||
s.PingTest()
|
||||
s.DownloadTest(false)
|
||||
s.UploadTest(false)
|
||||
|
||||
fmt.Printf("Latency: %s, Download: %f, Upload: %f\n", s.Latency, s.DLSpeed, s.ULSpeed)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
// add ping command to the main program
|
||||
rootCmd.AddCommand(netCmd)
|
||||
}
|
Reference in New Issue
Block a user