From 84b2cec9b513ff81a756126c4283c93ba53fe13e Mon Sep 17 00:00:00 2001 From: dudaodong Date: Tue, 30 May 2023 11:58:29 +0800 Subject: [PATCH] fix: fix PingConnected failed in win os --- netutil/net.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/netutil/net.go b/netutil/net.go index de4772e..72b92c6 100644 --- a/netutil/net.go +++ b/netutil/net.go @@ -12,6 +12,7 @@ import ( "net/url" "os" "os/exec" + "runtime" "strings" "time" @@ -242,11 +243,17 @@ func DownloadFile(filepath string, url string) error { // IsPingConnected checks if can ping specified host or not. 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 } + return true }