mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
fix: pruning wifi clients not seen in the last 5 minutes
This commit is contained in:
parent
81fb3fe1a6
commit
db30cfdd6a
2 changed files with 24 additions and 4 deletions
|
@ -29,11 +29,21 @@ func (w *WiFiModule) stationPruner() {
|
||||||
|
|
||||||
log.Debug("WiFi stations pruner started.")
|
log.Debug("WiFi stations pruner started.")
|
||||||
for w.Running() {
|
for w.Running() {
|
||||||
for _, s := range w.Session.WiFi.List() {
|
// loop every AP
|
||||||
sinceLastSeen := time.Since(s.LastSeen)
|
for _, ap := range w.Session.WiFi.List() {
|
||||||
|
sinceLastSeen := time.Since(ap.LastSeen)
|
||||||
if sinceLastSeen > maxStationTTL {
|
if sinceLastSeen > maxStationTTL {
|
||||||
log.Debug("Station %s not seen in %s, removing.", s.BSSID(), sinceLastSeen)
|
log.Debug("Station %s not seen in %s, removing.", ap.BSSID(), sinceLastSeen)
|
||||||
w.Session.WiFi.Remove(s.BSSID())
|
w.Session.WiFi.Remove(ap.BSSID())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// loop every AP client
|
||||||
|
for _, c := range ap.Clients() {
|
||||||
|
sinceLastSeen := time.Since(c.LastSeen)
|
||||||
|
if sinceLastSeen > maxStationTTL {
|
||||||
|
log.Debug("Client %s of station %s not seen in %s, removing.", c.String(), ap.BSSID(), sinceLastSeen)
|
||||||
|
ap.RemoveClient(c.BSSID())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
|
@ -49,6 +49,16 @@ func (ap *AccessPoint) Get(bssid string) (*Station, bool) {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ap *AccessPoint) RemoveClient(mac string) {
|
||||||
|
ap.Lock()
|
||||||
|
defer ap.Unlock()
|
||||||
|
|
||||||
|
bssid := NormalizeMac(mac)
|
||||||
|
if _, found := ap.clients[bssid]; found {
|
||||||
|
delete(ap.clients, bssid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (ap *AccessPoint) AddClient(bssid string, frequency int, rssi int8) *Station {
|
func (ap *AccessPoint) AddClient(bssid string, frequency int, rssi int8) *Station {
|
||||||
ap.Lock()
|
ap.Lock()
|
||||||
defer ap.Unlock()
|
defer ap.Unlock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue