mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -07:00
new: several improvements to the new.show u
This commit is contained in:
parent
646c5d14c7
commit
7abb3cbb2c
5 changed files with 135 additions and 104 deletions
|
@ -38,6 +38,7 @@ type Session struct {
|
|||
Targets *Targets `json:"targets"`
|
||||
Queue *packets.Queue `json:"packets"`
|
||||
Input *readline.Instance `json:"-"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
Active bool `json:"active"`
|
||||
Prompt Prompt `json:"-"`
|
||||
|
||||
|
@ -264,6 +265,7 @@ func (s *Session) Start() error {
|
|||
os.Exit(0)
|
||||
}()
|
||||
|
||||
s.StartedAt = time.Now()
|
||||
s.Active = true
|
||||
|
||||
// keep reading network events in order to add / update endpoints
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/evilsocket/bettercap-ng/net"
|
||||
)
|
||||
|
||||
const TargetsDefaultTTL = 2
|
||||
const TargetsAliasesFile = "~/bettercap.aliases"
|
||||
|
||||
type Targets struct {
|
||||
|
@ -47,6 +48,17 @@ func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets {
|
|||
return t
|
||||
}
|
||||
|
||||
func (tp *Targets) List() (list []*net.Endpoint) {
|
||||
tp.Lock()
|
||||
defer tp.Unlock()
|
||||
|
||||
list = make([]*net.Endpoint, 0)
|
||||
for _, t := range tp.Targets {
|
||||
list = append(list, t)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tp *Targets) loadAliases() error {
|
||||
tp.Session.Events.Log(core.INFO, "Loading aliases from %s ...", tp.aliasesFileName)
|
||||
file, err := os.Open(tp.aliasesFileName)
|
||||
|
@ -90,6 +102,20 @@ func (tp *Targets) SetAliasFor(mac, alias string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (tp *Targets) WasMissed(mac string) bool {
|
||||
if mac == tp.Session.Interface.HwAddress || mac == tp.Session.Gateway.HwAddress {
|
||||
return false
|
||||
}
|
||||
|
||||
tp.Lock()
|
||||
defer tp.Unlock()
|
||||
|
||||
if ttl, found := tp.TTL[mac]; found == true {
|
||||
return ttl < TargetsDefaultTTL
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (tp *Targets) Remove(ip, mac string) {
|
||||
tp.Lock()
|
||||
defer tp.Unlock()
|
||||
|
@ -145,7 +171,7 @@ func (tp *Targets) AddIfNotExist(ip, mac string) *net.Endpoint {
|
|||
}
|
||||
|
||||
tp.Targets[mac] = e
|
||||
tp.TTL[mac] = 2
|
||||
tp.TTL[mac] = TargetsDefaultTTL
|
||||
|
||||
tp.Session.Events.Add("target.new", e)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue