wangbin 3 days ago
parent b8fde018ee
commit be8bdd5a9b

@ -6,6 +6,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"runtime"
"net" "net"
"os" "os"
@ -1039,8 +1040,14 @@ func GetAvailableEndpoint() string {
} }
func IsIPReachable(ip string, port string) bool { func IsIPReachable(ip string, port string) bool {
var cmd *exec.Cmd
cmd := exec.Command("ping", "-c", "1", "-W", "1", ip) // 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 { if err := cmd.Run(); err == nil {
return true return true
} }

Loading…
Cancel
Save