mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 05:53:20 -07:00
new: main packet queue is now used to gather network stats, update endpoint, etc
This commit is contained in:
parent
a296dacd74
commit
913c581f9f
4 changed files with 127 additions and 15 deletions
|
@ -33,7 +33,7 @@ type Session struct {
|
|||
Firewall firewall.FirewallManager `json:"-"`
|
||||
Env *Environment `json:"env"`
|
||||
Targets *Targets `json:"targets"`
|
||||
Queue *packets.Queue `json:"-"`
|
||||
Queue *packets.Queue `json:"packets"`
|
||||
Input *readline.Instance `json:"-"`
|
||||
Active bool `json:"active"`
|
||||
Prompt Prompt `json:"-"`
|
||||
|
@ -174,7 +174,7 @@ func (s *Session) Start() error {
|
|||
s.Env.Set("iface.ipv6", s.Interface.Ip6Address)
|
||||
s.Env.Set("iface.mac", s.Interface.HwAddress)
|
||||
|
||||
if s.Queue, err = packets.NewQueue(s.Interface.Name()); err != nil {
|
||||
if s.Queue, err = packets.NewQueue(s.Interface); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -227,6 +227,20 @@ func (s *Session) Start() error {
|
|||
}()
|
||||
|
||||
s.Active = true
|
||||
|
||||
// keep reading network events in order to add / update endpoints
|
||||
go func() {
|
||||
for event := range s.Queue.Activities {
|
||||
addr := event.IP.String()
|
||||
mac := event.MAC.String()
|
||||
s.Targets.AddIfNotExist(addr, mac)
|
||||
|
||||
if s.Active == false {
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
s.Events.Add("session.started", nil)
|
||||
|
||||
return nil
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
"github.com/evilsocket/bettercap-ng/net"
|
||||
|
@ -63,6 +64,7 @@ func (tp *Targets) AddIfNotExist(ip, mac string) *net.Endpoint {
|
|||
}
|
||||
|
||||
if t, found := tp.Targets[mac]; found {
|
||||
t.LastSeen = time.Now()
|
||||
return t
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue