forked from jaypipes/ghw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
net.go
56 lines (48 loc) · 830 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
//
// Use and distribution licensed under the Apache license version 2.
//
// See the COPYING file in the root project directory for full text.
//
package ghw
import (
"fmt"
)
type NICCapability struct {
Name string
IsEnabled bool
CanChange bool
}
type NIC struct {
Name string
MacAddress string
IsVirtual bool
Capabilities []*NICCapability
}
func (n *NIC) String() string {
isVirtualStr := ""
if n.IsVirtual {
isVirtualStr = " (virtual)"
}
return fmt.Sprintf(
"%s%s",
n.Name,
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),
)
}