[agent][wdd] - 初始化项目
This commit is contained in:
25
agent-wdd/config/Network.go
Normal file
25
agent-wdd/config/Network.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user