diff --git a/Common/commonfunc.go b/Common/commonfunc.go index 11b0595..1fcc22c 100644 --- a/Common/commonfunc.go +++ b/Common/commonfunc.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "io" + "runtime" "net" "os" @@ -1039,8 +1040,14 @@ func GetAvailableEndpoint() string { } func IsIPReachable(ip string, port string) bool { - - cmd := exec.Command("ping", "-c", "1", "-W", "1", ip) + var cmd *exec.Cmd + // cmd := exec.Command("ping", "-c", "1", "-W", "1", ip) + timeout := 100 // 毫秒 + if runtime.GOOS == "windows" { + cmd = exec.Command("ping", "-n", "1", "-w", strconv.Itoa(timeout), ip) + } else { + cmd = exec.Command("ping", "-c", "1", "-W", strconv.Itoa(timeout/1000), ip) + } if err := cmd.Run(); err == nil { return true }