forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.go
59 lines (53 loc) · 924 Bytes
/
net.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
package ghw
import (
"fmt"
"strings"
)
type NIC struct {
Name string
BusType string
Driver string
MacAddress string
Model string
Vendor string
IsVirtual bool
EnabledFeatures []string
}
func (n *NIC) String() string {
vendorStr := ""
if n.Vendor != "" {
vendorStr = " [" + strings.TrimSpace(n.Vendor) + "]"
}
modelStr := ""
if n.Model != "" {
modelStr = " - " + strings.TrimSpace(n.Model)
}
isVirtualStr := ""
if n.IsVirtual {
isVirtualStr = " (virtual)"
}
return fmt.Sprintf(
"%s%s%s%s",
n.Name,
vendorStr,
modelStr,
isVirtualStr,
)
}
type NetworkInfo struct {
NICs []*NIC
}
func Network() (*NetworkInfo, error) {
info := &NetworkInfo{}
err := netFillInfo(info)
if err != nil {
return nil, err
}
return info, nil
}
func (i *NetworkInfo) String() string {
return fmt.Sprintf(
"net (%d NICs)",
len(i.NICs),
)
}