1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-07 06:02:27 +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"
"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
}