forked from bpicode/fritzctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_landevices.go
68 lines (58 loc) · 1.6 KB
/
list_landevices.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
67
68
package cmd
import (
"os"
"github.com/bpicode/fritzctl/assert"
"github.com/bpicode/fritzctl/console"
"github.com/bpicode/fritzctl/fritz"
"github.com/bpicode/fritzctl/logger"
"github.com/mitchellh/cli"
"github.com/olekukonko/tablewriter"
)
type listLandevicesCommand struct {
}
func (cmd *listLandevicesCommand) Help() string {
return "List the available LAN devices along with several information like IP addresses, MAC addresses, etc."
}
func (cmd *listLandevicesCommand) Synopsis() string {
return "list the available LAN devices"
}
func (cmd *listLandevicesCommand) Run(args []string) int {
c := clientLogin()
f := fritz.Internal(c)
devs, err := f.ListLanDevices()
assert.NoError(err, "cannot obtain LAN devices data:", err)
logger.Success("Obtained LAN devices data:")
table := cmd.table()
cmd.appendData(table, *devs)
table.Render()
return 0
}
func (cmd *listLandevicesCommand) table() *tablewriter.Table {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"NAME",
"IP",
"MAC",
"ACT/ONL",
"SPEED [Mbit/s]",
"COMPLIANCE",
})
return table
}
func (cmd *listLandevicesCommand) appendData(table *tablewriter.Table, devs fritz.LanDevices) {
for _, dev := range devs.Network {
table.Append([]string{
dev.Name,
dev.IP,
dev.Mac,
console.StringToCheckmark(dev.Active) + "/" + console.StringToCheckmark(dev.Online),
dev.Speed,
console.Stoc(dev.ParentalControlAbuse).Inverse().String(),
})
}
}
// ListLandevices is a factory creating commands for listing LAN devices.
func ListLandevices() (cli.Command, error) {
p := listLandevicesCommand{}
return &p, nil
}