mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
new: new wifi.ap.ttl and wifi.sta.ttl parameters
This commit is contained in:
parent
e3ed2ca5aa
commit
32e1bf8a7b
2 changed files with 24 additions and 5 deletions
|
@ -32,6 +32,8 @@ type WiFiModule struct {
|
||||||
region string
|
region string
|
||||||
txPower int
|
txPower int
|
||||||
minRSSI int
|
minRSSI int
|
||||||
|
apTTL int
|
||||||
|
staTTL int
|
||||||
channel int
|
channel int
|
||||||
hopPeriod time.Duration
|
hopPeriod time.Duration
|
||||||
hopChanges chan bool
|
hopChanges chan bool
|
||||||
|
@ -63,6 +65,8 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
||||||
SessionModule: session.NewSessionModule("wifi", s),
|
SessionModule: session.NewSessionModule("wifi", s),
|
||||||
iface: s.Interface,
|
iface: s.Interface,
|
||||||
minRSSI: -200,
|
minRSSI: -200,
|
||||||
|
apTTL: 300,
|
||||||
|
staTTL: 300,
|
||||||
channel: 0,
|
channel: 0,
|
||||||
stickChan: 0,
|
stickChan: 0,
|
||||||
hopPeriod: 250 * time.Millisecond,
|
hopPeriod: 250 * time.Millisecond,
|
||||||
|
@ -185,6 +189,14 @@ func NewWiFiModule(s *session.Session) *WiFiModule {
|
||||||
|
|
||||||
mod.AddHandler(assoc)
|
mod.AddHandler(assoc)
|
||||||
|
|
||||||
|
mod.AddParam(session.NewIntParameter("wifi.ap.ttl",
|
||||||
|
"300",
|
||||||
|
"Seconds of inactivity for an access points to be considered not in range anymore."))
|
||||||
|
|
||||||
|
mod.AddParam(session.NewIntParameter("wifi.sta.ttl",
|
||||||
|
"300",
|
||||||
|
"Seconds of inactivity for a client station to be considered not in range or not connected to its access point anymore."))
|
||||||
|
|
||||||
mod.AddParam(session.NewStringParameter("wifi.region",
|
mod.AddParam(session.NewStringParameter("wifi.region",
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
|
@ -354,6 +366,12 @@ func (mod *WiFiModule) Configure() error {
|
||||||
var hopPeriod int
|
var hopPeriod int
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
if err, mod.apTTL = mod.IntParam("wifi.ap.ttl"); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err, mod.staTTL = mod.IntParam("wifi.sta.ttl"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err, mod.region = mod.StringParam("wifi.region"); err != nil {
|
if err, mod.region = mod.StringParam("wifi.region"); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if err, mod.txPower = mod.IntParam("wifi.txpower"); err != nil {
|
} else if err, mod.txPower = mod.IntParam("wifi.txpower"); err != nil {
|
||||||
|
|
|
@ -11,18 +11,19 @@ import (
|
||||||
"github.com/google/gopacket/layers"
|
"github.com/google/gopacket/layers"
|
||||||
)
|
)
|
||||||
|
|
||||||
var maxStationTTL = 5 * time.Minute
|
|
||||||
|
|
||||||
func (mod *WiFiModule) stationPruner() {
|
func (mod *WiFiModule) stationPruner() {
|
||||||
mod.reads.Add(1)
|
mod.reads.Add(1)
|
||||||
defer mod.reads.Done()
|
defer mod.reads.Done()
|
||||||
|
|
||||||
mod.Debug("wifi stations pruner started.")
|
maxApTTL := time.Duration(mod.apTTL) * time.Second
|
||||||
|
maxStaTTL := time.Duration(mod.staTTL) * time.Second
|
||||||
|
|
||||||
|
mod.Debug("wifi stations pruner started (ap.ttl:%v sta.ttl:%v).", maxApTTL, maxStaTTL)
|
||||||
for mod.Running() {
|
for mod.Running() {
|
||||||
// loop every AP
|
// loop every AP
|
||||||
for _, ap := range mod.Session.WiFi.List() {
|
for _, ap := range mod.Session.WiFi.List() {
|
||||||
sinceLastSeen := time.Since(ap.LastSeen)
|
sinceLastSeen := time.Since(ap.LastSeen)
|
||||||
if sinceLastSeen > maxStationTTL {
|
if sinceLastSeen > maxApTTL {
|
||||||
mod.Debug("station %s not seen in %s, removing.", ap.BSSID(), sinceLastSeen)
|
mod.Debug("station %s not seen in %s, removing.", ap.BSSID(), sinceLastSeen)
|
||||||
mod.Session.WiFi.Remove(ap.BSSID())
|
mod.Session.WiFi.Remove(ap.BSSID())
|
||||||
continue
|
continue
|
||||||
|
@ -30,7 +31,7 @@ func (mod *WiFiModule) stationPruner() {
|
||||||
// loop every AP client
|
// loop every AP client
|
||||||
for _, c := range ap.Clients() {
|
for _, c := range ap.Clients() {
|
||||||
sinceLastSeen := time.Since(c.LastSeen)
|
sinceLastSeen := time.Since(c.LastSeen)
|
||||||
if sinceLastSeen > maxStationTTL {
|
if sinceLastSeen > maxStaTTL {
|
||||||
mod.Debug("client %s of station %s not seen in %s, removing.", c.String(), ap.BSSID(), sinceLastSeen)
|
mod.Debug("client %s of station %s not seen in %s, removing.", c.String(), ap.BSSID(), sinceLastSeen)
|
||||||
ap.RemoveClient(c.BSSID())
|
ap.RemoveClient(c.BSSID())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue