1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

fix: fix IsPingConnected failed in windows

This commit is contained in:
dudaodong
2023-04-26 19:53:53 +08:00
parent 33c8875d14
commit 4888909208
2 changed files with 8 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ import (
"net/url"
"os"
"os/exec"
"runtime"
"strings"
"time"
@@ -251,7 +252,12 @@ func DownloadFile(filepath string, url string) error {
// IsPingConnected checks if can ping specified host or not.
// Play: todo
func IsPingConnected(host string) bool {
cmd := exec.Command("ping", host, "-c", "1", "-W", "6")
cmd := exec.Command("ping", host, "-c", "4", "-W", "6")
if runtime.GOOS == "windows" {
cmd = exec.Command("ping", host, "-n", "4", "-w", "6")
}
err := cmd.Run()
if err != nil {
return false

View File

@@ -121,7 +121,7 @@ func TestIsPingConnected(t *testing.T) {
assert := internal.NewAssert(t, "TestIsPingConnected")
// in github action env, this will fail
// result1 := IsPingConnected("bing.com")
// result1 := IsPingConnected("www.baidu.com")
// assert.Equal(true, result1)
result2 := IsPingConnected("www.!@#&&&.com")