wangbin 3 days ago
parent b8fde018ee
commit be8bdd5a9b

@ -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
}

Loading…
Cancel
Save