[agent][wdd] - 初始化项目
This commit is contained in:
67
agent-wdd/config/Info.go
Normal file
67
agent-wdd/config/Info.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type AgentServerInfo struct {
|
||||
NetworkInfo
|
||||
CPUInfo
|
||||
}
|
||||
|
||||
type NetworkInfo struct {
|
||||
Interfaces []InterfaceInfo
|
||||
}
|
||||
|
||||
type InterfaceInfo struct {
|
||||
Name string
|
||||
HardwareAddr string
|
||||
Addrs []string
|
||||
}
|
||||
|
||||
func GetNetworkInfo() (*NetworkInfo, error) {
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var networkInfo NetworkInfo
|
||||
for _, iface := range interfaces {
|
||||
var addrs []string
|
||||
addresses, err := iface.Addrs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, addr := range addresses {
|
||||
addrs = append(addrs, addr.String())
|
||||
}
|
||||
|
||||
interfaceInfo := InterfaceInfo{
|
||||
Name: iface.Name,
|
||||
HardwareAddr: iface.HardwareAddr.String(),
|
||||
Addrs: addrs,
|
||||
}
|
||||
networkInfo.Interfaces = append(networkInfo.Interfaces, interfaceInfo)
|
||||
}
|
||||
|
||||
return &networkInfo, nil
|
||||
}
|
||||
|
||||
type CPUInfo struct {
|
||||
ModelName string
|
||||
Cores int
|
||||
Mhz float64
|
||||
}
|
||||
|
||||
func GetCpuInfo() CPUInfo {
|
||||
info := CPUInfo{}
|
||||
info.ModelName = runtime.GOARCH
|
||||
info.Cores = runtime.NumCPU()
|
||||
info.Mhz = 0.0
|
||||
return info
|
||||
}
|
||||
|
||||
func (info *AgentServerInfo) GetAgentInfo() {
|
||||
|
||||
}
|
||||
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