new: several improvements to the new.show u

This commit is contained in:
evilsocket 2018-01-29 12:26:28 +01:00
commit 7abb3cbb2c
5 changed files with 135 additions and 104 deletions

View file

@ -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)