mirror of
https://github.com/bettercap/bettercap
synced 2025-08-13 02:06:57 -07:00
new: new limit optional argument for events.show
This commit is contained in:
parent
1353c47056
commit
3c2932514a
4 changed files with 37 additions and 24 deletions
|
@ -1,6 +1,9 @@
|
|||
package modules
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
"github.com/evilsocket/bettercap-ng/session"
|
||||
)
|
||||
|
||||
|
@ -34,10 +37,15 @@ func NewEventsStream(s *session.Session) *EventsStream {
|
|||
return stream.Stop()
|
||||
}))
|
||||
|
||||
stream.AddHandler(session.NewModuleHandler("events.show", "",
|
||||
stream.AddHandler(session.NewModuleHandler("events.show LIMIT?", "events.show(\\s\\d+)?",
|
||||
"Show events stream.",
|
||||
func(args []string) error {
|
||||
return stream.Show()
|
||||
limit := -1
|
||||
if len(args) == 1 {
|
||||
arg := core.Trim(args[0])
|
||||
limit, _ = strconv.Atoi(arg)
|
||||
}
|
||||
return stream.Show(limit)
|
||||
}))
|
||||
|
||||
stream.AddHandler(session.NewModuleHandler("events.clear", "",
|
||||
|
@ -96,8 +104,16 @@ func (s *EventsStream) Start() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *EventsStream) Show() error {
|
||||
for _, e := range s.Session.Events.Sorted() {
|
||||
func (s *EventsStream) Show(limit int) error {
|
||||
events := s.Session.Events.Sorted()
|
||||
num := len(events)
|
||||
from := 0
|
||||
|
||||
if limit > 0 && num > limit {
|
||||
from = num - limit
|
||||
}
|
||||
|
||||
for _, e := range events[from:num] {
|
||||
s.View(e, false)
|
||||
}
|
||||
|
||||
|
|
|
@ -34,13 +34,6 @@ func (s EventsStream) viewEndpointEvent(e session.Event) {
|
|||
t.HwAddress,
|
||||
core.Bold(t.IpAddress),
|
||||
extra)
|
||||
} else if e.Tag == "endpoint.resolved" {
|
||||
if *session.I.Options.Debug {
|
||||
fmt.Printf("[%s] Endpoint %s resolved as %s.\n",
|
||||
e.Time.Format(eventTimeFormat),
|
||||
core.Bold(t.IpAddress),
|
||||
core.Yellow(t.Hostname))
|
||||
}
|
||||
} else if e.Tag == "endpoint.lost" {
|
||||
fmt.Printf("[%s] Endpoint %s lost.\n",
|
||||
e.Time.Format(eventTimeFormat),
|
||||
|
@ -54,12 +47,12 @@ func (s EventsStream) viewEndpointEvent(e session.Event) {
|
|||
}
|
||||
|
||||
func (s EventsStream) viewModuleEvent(e session.Event) {
|
||||
if *session.I.Options.Debug == true {
|
||||
// if *session.I.Options.Debug == true {
|
||||
fmt.Printf("[%s] [%s] %s\n",
|
||||
e.Time.Format(eventTimeFormat),
|
||||
core.Green(e.Tag),
|
||||
e.Data)
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
func (s EventsStream) viewSnifferEvent(e session.Event) {
|
||||
|
|
|
@ -127,9 +127,11 @@ func (m *SessionModule) SetRunning(running bool) {
|
|||
defer m.StatusLock.Unlock()
|
||||
m.Started = running
|
||||
|
||||
if *m.Session.Options.Debug == true {
|
||||
if running {
|
||||
m.Session.Events.Add("mod.started", m.Name)
|
||||
} else {
|
||||
m.Session.Events.Add("mod.stopped", m.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,9 +185,11 @@ func (tp *Targets) AddIfNew(ip, mac string) *bnet.Endpoint {
|
|||
}
|
||||
|
||||
e := bnet.NewEndpoint(ip, mac)
|
||||
/*
|
||||
e.ResolvedCallback = func(e *bnet.Endpoint) {
|
||||
tp.Session.Events.Add("endpoint.resolved", e)
|
||||
}
|
||||
*/
|
||||
|
||||
if alias, found := tp.Aliases[mac]; found {
|
||||
e.Alias = alias
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue