[agent][wdd] - 初始化项目

This commit is contained in:
zeaslity
2025-02-10 15:07:44 +08:00
parent a0811d62e7
commit b8f0b14852
12 changed files with 455 additions and 0 deletions

67
agent-wdd/config/Info.go Normal file
View 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() {
}

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