Files
ProjectOctopus/agent-wdd/config/Network.go
2025-02-10 15:07:44 +08:00

26 lines
485 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"net/http"
"time"
)
// CanConnectInternet 判定主机能否上网 请求 www.google.com 如果请求正常 返回2 如果超时三秒 请求baidu.com如果没有错误返回1 如果错误返回0
func CanConnectInternet() int {
client := http.Client{
Timeout: 3 * time.Second,
}
_, err := client.Get("https://www.google.com")
if err == nil {
return 2
}
_, err = client.Get("https://www.baidu.com")
if err == nil {
return 1
}
return 0
}