-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (50 loc) · 987 Bytes
/
main.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
package main
import (
"bufio"
"fmt"
"log"
"net"
"os"
)
func main() {
hostName, err := os.Hostname()
if err != nil {
log.Fatal(err)
}
addresses, err := getMacAddr()
if err != nil {
log.Fatal(err)
}
display(hostName, addresses)
waitExit()
}
func getMacAddr() ([]string, error) {
interfaces, err := net.Interfaces()
if err != nil {
return nil, err
}
var macAddresses []string
for _, i := range interfaces {
a := i.HardwareAddr.String()
if a != "" {
macAddresses = append(macAddresses, a)
}
}
return macAddresses, nil
}
func display(hostName string, macAddresses []string) {
fmt.Println("------------------------------")
fmt.Println("- Hostname")
fmt.Println(hostName)
fmt.Println("")
fmt.Println("- MAC Addresses")
for _, a := range macAddresses {
fmt.Println(a)
}
fmt.Println("------------------------------")
}
func waitExit() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Please Enter key to exit.")
reader.ReadString('\n')
}