Skip to content

Commit

Permalink
feat: add --force-http-ping flag (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
r3inbowari authored Jun 4, 2023
1 parent 103bb9f commit 7b47f96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Flags:
--search=SEARCH Fuzzy search servers by a keyword.
--no-download Disable download test.
--no-upload Disable upload test.
--force-http-ping Force ping using http.
-d --debug Enable debug mode.
--version Show application version.
```
Expand Down Expand Up @@ -172,19 +173,19 @@ func main() {
// Select a network card as the data interface.
// speedtest.WithUserConfig(&speedtest.UserConfig{Source: "192.168.1.101"})(speedtestClient)

user, _ := speedtestClient.FetchUserInfo()
// user, _ := speedtestClient.FetchUserInfo()
// Get a list of servers near a specified location
// user.SetLocationByCity("Tokyo")
// user.SetLocation("Osaka", 34.6952, 135.5006)

serverList, _ := speedtestClient.FetchServers(user)
serverList, _ := speedtestClient.FetchServers()
targets, _ := serverList.FindServer([]int{})

for _, s := range targets {
// Please make sure your host can access this test server,
// otherwise you will get an error.
// It is recommended to replace a server at this time
s.PingTest()
s.PingTest(nil)
s.DownloadTest()
s.UploadTest()
fmt.Printf("Latency: %s, Download: %f, Upload: %f\n", s.Latency, s.DLSpeed, s.ULSpeed)
Expand Down
35 changes: 18 additions & 17 deletions speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ import (
)

var (
showList = kingpin.Flag("list", "Show available speedtest.net servers.").Short('l').Bool()
serverIds = kingpin.Flag("server", "Select server id to run speedtest.").Short('s').Ints()
customURL = kingpin.Flag("custom-url", "Specify the url of the server instead of getting a list from speedtest.net.").String()
savingMode = kingpin.Flag("saving-mode", "Test with few resources, though low accuracy (especially > 30Mbps).").Bool()
jsonOutput = kingpin.Flag("json", "Output results in json format.").Bool()
location = kingpin.Flag("location", "Change the location with a precise coordinate. Format: lat,lon").String()
city = kingpin.Flag("city", "Change the location with a predefined city label.").String()
showCityList = kingpin.Flag("city-list", "List all predefined city labels.").Bool()
proxy = kingpin.Flag("proxy", "Set a proxy(http[s] or socks) for the speedtest.").String()
source = kingpin.Flag("source", "Bind a source interface for the speedtest.").String()
multi = kingpin.Flag("multi", "Enable multi-server mode.").Short('m').Bool()
thread = kingpin.Flag("thread", "Set the number of concurrent connections.").Short('t').Int()
search = kingpin.Flag("search", "Fuzzy search servers by a keyword.").String()
noDownload = kingpin.Flag("no-download", "Disable download test.").Bool()
noUpload = kingpin.Flag("no-upload", "Disable upload test.").Bool()
debug = kingpin.Flag("debug", "Enable debug mode.").Short('d').Bool()
showList = kingpin.Flag("list", "Show available speedtest.net servers.").Short('l').Bool()
serverIds = kingpin.Flag("server", "Select server id to run speedtest.").Short('s').Ints()
customURL = kingpin.Flag("custom-url", "Specify the url of the server instead of getting a list from speedtest.net.").String()
savingMode = kingpin.Flag("saving-mode", "Test with few resources, though low accuracy (especially > 30Mbps).").Bool()
jsonOutput = kingpin.Flag("json", "Output results in json format.").Bool()
location = kingpin.Flag("location", "Change the location with a precise coordinate. Format: lat,lon").String()
city = kingpin.Flag("city", "Change the location with a predefined city label.").String()
showCityList = kingpin.Flag("city-list", "List all predefined city labels.").Bool()
proxy = kingpin.Flag("proxy", "Set a proxy(http[s] or socks) for the speedtest.").String()
source = kingpin.Flag("source", "Bind a source interface for the speedtest.").String()
multi = kingpin.Flag("multi", "Enable multi-server mode.").Short('m').Bool()
thread = kingpin.Flag("thread", "Set the number of concurrent connections.").Short('t').Int()
search = kingpin.Flag("search", "Fuzzy search servers by a keyword.").String()
noDownload = kingpin.Flag("no-download", "Disable download test.").Bool()
noUpload = kingpin.Flag("no-upload", "Disable upload test.").Bool()
forceHTTPPing = kingpin.Flag("force-http-ping", "Force ping using http.").Bool()
debug = kingpin.Flag("debug", "Enable debug mode.").Short('d').Bool()
)

func main() {
Expand All @@ -42,7 +43,7 @@ func main() {
Proxy: *proxy,
Source: *source,
Debug: *debug,
ICMP: (os.Geteuid() == 0 || os.Geteuid() == -1) && len(*proxy) == 0, // proxy may not support ICMP
ICMP: (os.Geteuid() == 0 || os.Geteuid() == -1) && len(*proxy) == 0 && !*forceHTTPPing, // proxy may not support ICMP
SavingMode: *savingMode,
CityFlag: *city,
LocationFlag: *location,
Expand Down

0 comments on commit 7b47f96

Please sign in to comment.