| | |
| | | package licence |
| | | |
| | | import ( |
| | | "sort" |
| | | "strconv" |
| | | "strings" |
| | | |
| | | "github.com/shirou/gopsutil/cpu" |
| | |
| | | ) |
| | | |
| | | func GetMachineCode() string { |
| | | var machineCode string |
| | | var machineInfo []string |
| | | |
| | | // CPU |
| | | if cpu, err := cpu.Info(); err == nil { |
| | | for _, c := range cpu { |
| | | machineCode = strings.Join([]string{machineCode, c.String()}, "-cpu-") |
| | | if cnt, err := cpu.Counts(true); err == nil { |
| | | machineInfo = append(machineInfo, "cpuCounts:"+strconv.Itoa(cnt)) |
| | | if cnt > 0 { |
| | | if c, err := cpu.Info(); err == nil { |
| | | machineInfo = append(machineInfo, "cpuModelName:"+c[0].ModelName) |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if diskInfo, err := disk.Partitions(false); err == nil { |
| | | for _, d := range diskInfo { |
| | | diskSerialNumber := disk.GetDiskSerialNumber(d.Device) |
| | | strings.Join([]string{machineCode, diskSerialNumber}, "-") |
| | | machineInfo = append(machineInfo, diskSerialNumber) |
| | | } |
| | | } |
| | | |
| | | // Host |
| | | if host, err := host.Info(); err == nil { |
| | | machineCode = strings.Join([]string{machineCode, host.HostID}, "-host-") |
| | | machineInfo = append(machineInfo, host.HostID) |
| | | }*/ |
| | | |
| | | // Net |
| | | if net, err := psnet.Interfaces(); err == nil { |
| | | for _, n := range net { |
| | | if n.MTU == 1500 && !VNetFilter(&n) { |
| | | machineCode = strings.Join([]string{machineCode, n.HardwareAddr}, "-mac-") |
| | | machineInfo = append(machineInfo, "mac:"+n.HardwareAddr) |
| | | } |
| | | } |
| | | } |
| | | |
| | | return GetMd5String(machineCode, true, false) |
| | | sort.Strings(machineInfo) |
| | | |
| | | return GetMd5String(strings.Join(machineInfo, "-|-"), true, false) |
| | | } |
| | | |
| | | func VNetFilter(iface *psnet.InterfaceStat) bool { |