misc: small fix or general refactoring i did not bother commenting

This commit is contained in:
evilsocket 2018-02-19 20:58:10 +01:00
parent 420ab9e26c
commit b4df469ff1
2 changed files with 16 additions and 17 deletions

View file

@ -311,7 +311,7 @@ func (w *WiFiRecon) startDeauth(apMac net.HardwareAddr, clMac net.HardwareAddr)
} else { } else {
log.Info("Deauthing clients from AP %s ...", apMac.String()) log.Info("Deauthing clients from AP %s ...", apMac.String())
// deauth every authenticated client // deauth every authenticated client
for _, station := range w.Session.WiFi.Stations { for _, station := range w.Session.WiFi.List() {
if station.IsAP == false { if station.IsAP == false {
w.sendDeauthPacket(apMac, station.HW) w.sendDeauthPacket(apMac, station.HW)
} }

View file

@ -10,19 +10,18 @@ type StationLostCallback func(s *Station)
type WiFi struct { type WiFi struct {
sync.Mutex sync.Mutex
Interface *Endpoint iface *Endpoint
Stations map[string]*Station stations map[string]*Station
newCb StationNewCallback
newCb StationNewCallback lostCb StationLostCallback
lostCb StationLostCallback
} }
func NewWiFi(iface *Endpoint, newcb StationNewCallback, lostcb StationLostCallback) *WiFi { func NewWiFi(iface *Endpoint, newcb StationNewCallback, lostcb StationLostCallback) *WiFi {
return &WiFi{ return &WiFi{
Interface: iface, iface: iface,
Stations: make(map[string]*Station), stations: make(map[string]*Station),
newCb: newcb, newCb: newcb,
lostCb: lostcb, lostCb: lostcb,
} }
} }
@ -31,7 +30,7 @@ func (w *WiFi) List() (list []*Station) {
defer w.Unlock() defer w.Unlock()
list = make([]*Station, 0) list = make([]*Station, 0)
for _, t := range w.Stations { for _, t := range w.stations {
list = append(list, t) list = append(list, t)
} }
return return
@ -41,8 +40,8 @@ func (w *WiFi) Remove(mac string) {
w.Lock() w.Lock()
defer w.Unlock() defer w.Unlock()
if s, found := w.Stations[mac]; found { if s, found := w.stations[mac]; found {
delete(w.Stations, mac) delete(w.stations, mac)
if w.lostCb != nil { if w.lostCb != nil {
w.lostCb(s) w.lostCb(s)
} }
@ -54,14 +53,14 @@ func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int, rssi int8) *St
defer w.Unlock() defer w.Unlock()
mac = NormalizeMac(mac) mac = NormalizeMac(mac)
if station, found := w.Stations[mac]; found { if station, found := w.stations[mac]; found {
station.LastSeen = time.Now() station.LastSeen = time.Now()
station.RSSI = rssi station.RSSI = rssi
return station return station
} }
newStation := NewStation(ssid, mac, isAp, channel, rssi) newStation := NewStation(ssid, mac, isAp, channel, rssi)
w.Stations[mac] = newStation w.stations[mac] = newStation
if w.newCb != nil { if w.newCb != nil {
w.newCb(newStation) w.newCb(newStation)
@ -75,11 +74,11 @@ func (w *WiFi) Get(mac string) (*Station, bool) {
defer w.Unlock() defer w.Unlock()
mac = NormalizeMac(mac) mac = NormalizeMac(mac)
station, found := w.Stations[mac] station, found := w.stations[mac]
return station, found return station, found
} }
func (w *WiFi) Clear() error { func (w *WiFi) Clear() error {
w.Stations = make(map[string]*Station) w.stations = make(map[string]*Station)
return nil return nil
} }