mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
new: showing last events in net.show instead of useless histogram
This commit is contained in:
parent
3d7c19b071
commit
eb1a53efa3
4 changed files with 50 additions and 21 deletions
|
@ -84,7 +84,7 @@ func (s *EventsStream) Start() error {
|
||||||
var e session.Event
|
var e session.Event
|
||||||
select {
|
select {
|
||||||
case e = <-s.Session.Events.NewEvents:
|
case e = <-s.Session.Events.NewEvents:
|
||||||
s.view(e)
|
s.View(e, true)
|
||||||
break
|
break
|
||||||
|
|
||||||
case <-s.quit:
|
case <-s.quit:
|
||||||
|
@ -98,9 +98,11 @@ func (s *EventsStream) Start() error {
|
||||||
|
|
||||||
func (s *EventsStream) Show() error {
|
func (s *EventsStream) Show() error {
|
||||||
for _, e := range s.Session.Events.Sorted() {
|
for _, e := range s.Session.Events.Sorted() {
|
||||||
s.view(e)
|
s.View(e, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.Session.Refresh()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (s EventsStream) viewSnifferEvent(e session.Event) {
|
||||||
se.Data)
|
se.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EventsStream) view(e session.Event) {
|
func (s *EventsStream) View(e session.Event, refresh bool) {
|
||||||
if s.filter == "" || strings.Contains(e.Tag, s.filter) {
|
if s.filter == "" || strings.Contains(e.Tag, s.filter) {
|
||||||
if e.Tag == "sys.log" {
|
if e.Tag == "sys.log" {
|
||||||
s.viewLogEvent(e)
|
s.viewLogEvent(e)
|
||||||
|
@ -38,6 +38,8 @@ func (s *EventsStream) view(e session.Event) {
|
||||||
fmt.Printf("[%s] [%s] %v\n", e.Time.Format(eventTimeFormat), core.Green(e.Tag), e)
|
fmt.Printf("[%s] [%s] %v\n", e.Time.Format(eventTimeFormat), core.Green(e.Tag), e)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Session.Refresh()
|
if refresh {
|
||||||
|
s.Session.Refresh()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,30 +144,55 @@ func (d *Discovery) Show(by string) error {
|
||||||
|
|
||||||
d.showTable([]string{"IP", "MAC", "Name", "Vendor", "Sent", "Recvd", "Last Seen"}, rows)
|
d.showTable([]string{"IP", "MAC", "Name", "Vendor", "Sent", "Recvd", "Last Seen"}, rows)
|
||||||
|
|
||||||
rows = [][]string{{
|
fmt.Printf("\n%s %s / %s %s / %d pkts / %d errs\n\n",
|
||||||
|
core.Red("↑"),
|
||||||
humanize.Bytes(d.Session.Queue.Sent),
|
humanize.Bytes(d.Session.Queue.Sent),
|
||||||
|
core.Green("↓"),
|
||||||
humanize.Bytes(d.Session.Queue.Received),
|
humanize.Bytes(d.Session.Queue.Received),
|
||||||
fmt.Sprintf("%d", d.Session.Queue.PktReceived),
|
d.Session.Queue.PktReceived,
|
||||||
fmt.Sprintf("%d", d.Session.Queue.Errors),
|
d.Session.Queue.Errors)
|
||||||
}}
|
|
||||||
|
|
||||||
d.showTable([]string{"Sent", "Sniffed", "# Packets", "Errors"}, rows)
|
s := EventsStream{}
|
||||||
|
events := d.Session.Events.Sorted()
|
||||||
|
size := len(events)
|
||||||
|
|
||||||
rows = make([][]string, 0)
|
if size > 0 {
|
||||||
protos, maxPackets := rankByProtoHits(d.Session.Queue.Protos)
|
max := 20
|
||||||
maxBarWidth := 70
|
if size > max {
|
||||||
|
from := size - max
|
||||||
for _, p := range protos {
|
size = max
|
||||||
width := int(float32(maxBarWidth) * (float32(p.Hits) / float32(maxPackets)))
|
events = events[from:]
|
||||||
bar := ""
|
|
||||||
for i := 0; i < width; i++ {
|
|
||||||
bar += "▇"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rows = append(rows, []string{p.Protocol, fmt.Sprintf("%s %d", bar, p.Hits)})
|
fmt.Printf("Last %d events:\n\n", size)
|
||||||
|
|
||||||
|
for _, e := range events {
|
||||||
|
s.View(e, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
d.showTable([]string{"Proto", "# Packets"}, rows)
|
/*
|
||||||
|
Last events are more useful than this histogram and vertical scroll
|
||||||
|
isn't infinite :)
|
||||||
|
|
||||||
|
rows = make([][]string, 0)
|
||||||
|
protos, maxPackets := rankByProtoHits(d.Session.Queue.Protos)
|
||||||
|
maxBarWidth := 70
|
||||||
|
|
||||||
|
for _, p := range protos {
|
||||||
|
width := int(float32(maxBarWidth) * (float32(p.Hits) / float32(maxPackets)))
|
||||||
|
bar := ""
|
||||||
|
for i := 0; i < width; i++ {
|
||||||
|
bar += "▇"
|
||||||
|
}
|
||||||
|
|
||||||
|
rows = append(rows, []string{p.Protocol, fmt.Sprintf("%s %d", bar, p.Hits)})
|
||||||
|
}
|
||||||
|
|
||||||
|
d.showTable([]string{"Proto", "# Packets"}, rows)
|
||||||
|
*/
|
||||||
|
|
||||||
d.Session.Refresh()
|
d.Session.Refresh()
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ func (s *Session) clsHandler(args []string, sess *Session) error {
|
||||||
// fixes a weird bug which causes the screen not to be fully
|
// fixes a weird bug which causes the screen not to be fully
|
||||||
// cleared if a "clear; net.show" commands chain is executed
|
// cleared if a "clear; net.show" commands chain is executed
|
||||||
// in the interactive session.
|
// in the interactive session.
|
||||||
for i := 0; i < 80; i++ {
|
for i := 0; i < 180; i++ {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
readline.ClearScreen(s.Input.Stdout())
|
readline.ClearScreen(s.Input.Stdout())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue