mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -07:00
new: new can module for CAN-bus
This commit is contained in:
parent
9937e797ae
commit
5fe3ef3d52
12 changed files with 755 additions and 3 deletions
50
modules/can/can_show.go
Normal file
50
modules/can/can_show.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package can
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/network"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/evilsocket/islazy/tui"
|
||||
)
|
||||
|
||||
var (
|
||||
AliveTimeInterval = time.Duration(5) * time.Minute
|
||||
PresentTimeInterval = time.Duration(1) * time.Minute
|
||||
JustJoinedTimeInterval = time.Duration(10) * time.Second
|
||||
)
|
||||
|
||||
func (mod *CANModule) getRow(dev *network.CANDevice) []string {
|
||||
sinceLastSeen := time.Since(dev.LastSeen)
|
||||
seen := dev.LastSeen.Format("15:04:05")
|
||||
|
||||
if sinceLastSeen <= JustJoinedTimeInterval {
|
||||
seen = tui.Bold(seen)
|
||||
} else if sinceLastSeen > PresentTimeInterval {
|
||||
seen = tui.Dim(seen)
|
||||
}
|
||||
|
||||
return []string{
|
||||
dev.Name,
|
||||
dev.Description,
|
||||
humanize.Bytes(dev.Read),
|
||||
seen,
|
||||
}
|
||||
}
|
||||
|
||||
func (mod *CANModule) Show() (err error) {
|
||||
devices := mod.Session.CAN.Devices()
|
||||
|
||||
rows := make([][]string, 0)
|
||||
for _, dev := range devices {
|
||||
rows = append(rows, mod.getRow(dev))
|
||||
}
|
||||
|
||||
tui.Table(mod.Session.Events.Stdout, []string{"Name", "Description", "Data", "Seen"}, rows)
|
||||
|
||||
if len(rows) > 0 {
|
||||
mod.Session.Refresh()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue