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:
@@ -11,6 +11,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -251,7 +252,12 @@ func DownloadFile(filepath string, url string) error {
|
|||||||
// IsPingConnected checks if can ping specified host or not.
|
// IsPingConnected checks if can ping specified host or not.
|
||||||
// Play: todo
|
// Play: todo
|
||||||
func IsPingConnected(host string) bool {
|
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()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ func TestIsPingConnected(t *testing.T) {
|
|||||||
assert := internal.NewAssert(t, "TestIsPingConnected")
|
assert := internal.NewAssert(t, "TestIsPingConnected")
|
||||||
|
|
||||||
// in github action env, this will fail
|
// in github action env, this will fail
|
||||||
// result1 := IsPingConnected("bing.com")
|
// result1 := IsPingConnected("www.baidu.com")
|
||||||
// assert.Equal(true, result1)
|
// assert.Equal(true, result1)
|
||||||
|
|
||||||
result2 := IsPingConnected("www.!@#&&&.com")
|
result2 := IsPingConnected("www.!@#&&&.com")
|
||||||
|
|||||||
Reference in New Issue
Block a user