-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
profile.go
64 lines (55 loc) · 1.56 KB
/
profile.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
// Kraken
// Copyright (C) 2016-2020 Claudio Guarnieri
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package main
import (
"fmt"
"net"
"os"
"os/user"
"github.com/botherder/go-savetime/hashes"
"github.com/matishsiao/goInfo"
)
// For a machine ID we use a SHA1 of the first Mac address we find.
// TODO: should rather use the disk serial number.
func getMachineID() string {
ifaces, _ := net.Interfaces()
for _, iface := range ifaces {
mac := iface.HardwareAddr.String()
if len(mac) == 17 {
hash, _ := hashes.StringSHA1(mac)
return hash
}
}
return ""
}
// Get current username.
func getUserName() string {
userObject, err := user.Current()
if err != nil {
return ""
}
return userObject.Username
}
// Get computer name.
func getComputerName() string {
hostname, _ := os.Hostname()
return hostname
}
// Get some accurate version of the operating system.
func getOperatingSystem() string {
gi := goInfo.GetInfo()
return fmt.Sprintf("%s %s", gi.OS, gi.Core)
}