1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-23 13:52:26 +08:00

fix: fix PingConnected failed in win os

This commit is contained in:
dudaodong
2023-05-30 11:58:29 +08:00
parent 2d01a13787
commit 84b2cec9b5

View File

@@ -12,6 +12,7 @@ import (
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
"runtime"
"strings" "strings"
"time" "time"
@@ -242,11 +243,17 @@ 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.
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
} }
return true return true
} }