mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
fix: using ttl counters for hosts making host discovery way more stable
This commit is contained in:
parent
5c2dc44a2d
commit
883f200e85
1 changed files with 9 additions and 2 deletions
|
@ -11,6 +11,7 @@ type Targets struct {
|
||||||
Interface *net.Endpoint
|
Interface *net.Endpoint
|
||||||
Gateway *net.Endpoint
|
Gateway *net.Endpoint
|
||||||
Targets map[string]*net.Endpoint
|
Targets map[string]*net.Endpoint
|
||||||
|
TTL map[string]uint
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets {
|
||||||
Interface: iface,
|
Interface: iface,
|
||||||
Gateway: gateway,
|
Gateway: gateway,
|
||||||
Targets: make(map[string]*net.Endpoint),
|
Targets: make(map[string]*net.Endpoint),
|
||||||
|
TTL: make(map[string]uint),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +38,12 @@ func (tp *Targets) Remove(ip, mac string) {
|
||||||
defer tp.lock.Unlock()
|
defer tp.lock.Unlock()
|
||||||
|
|
||||||
if e, found := tp.Targets[mac]; found {
|
if e, found := tp.Targets[mac]; found {
|
||||||
|
tp.TTL[mac]--
|
||||||
|
if tp.TTL[mac] == 0 {
|
||||||
tp.Session.Events.Add("target.lost", e)
|
tp.Session.Events.Add("target.lost", e)
|
||||||
delete(tp.Targets, mac)
|
delete(tp.Targets, mac)
|
||||||
|
delete(tp.TTL, mac)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +83,7 @@ func (tp *Targets) AddIfNotExist(ip, mac string) *net.Endpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
tp.Targets[mac] = e
|
tp.Targets[mac] = e
|
||||||
|
tp.TTL[mac] = 2
|
||||||
|
|
||||||
tp.Session.Events.Add("target.new", e)
|
tp.Session.Events.Add("target.new", e)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue