-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsys_info.go
66 lines (60 loc) · 1.34 KB
/
sys_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package pencake
import (
"io/ioutil"
"net/http"
"os"
"os/user"
"pencake/utils"
"strings"
)
func SysInfo() SysInfoStruct {
switch utils.SystemType() {
case "windows":
return getWindowsSysInfo()
default:
return getUnixSysInfo()
}
}
type SysInfoStruct struct {
Os string
Arch string
UserName string
Name string
IsAdmin bool
PublicIp string
}
func getPublicIp() string {
resp, _ := http.Get("https://ifconfig.me")
publicIp, _ := ioutil.ReadAll(resp.Body)
return string(publicIp)
}
func getUnixSysInfo() SysInfoStruct {
var result SysInfoStruct
userInfo, _ := user.Current()
result.Os = utils.SystemType()
result.Arch = utils.RunCommand("uname -m")
result.UserName = userInfo.Username
result.Name = userInfo.Name
result.IsAdmin = os.Getuid() == 0
result.PublicIp = getPublicIp()
return result
}
func getWindowsSysInfo() SysInfoStruct {
var result SysInfoStruct
result.Os = "windows"
archInfos := strings.Split(utils.RunCommand("wmic os get osarchitecture"), "\n")
if len(archInfos) > 1 {
result.Arch = archInfos[1]
} else {
result.Arch = "UNKNOWN"
}
userInfo, _ := user.Current()
result.UserName = userInfo.Username
result.Name = userInfo.Name
userSID := userInfo.Gid
if len(userSID) > 4 && userSID[len(userSID)-5:] == "-500" {
result.IsAdmin = true
}
result.PublicIp = getPublicIp()
return result
}