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

This commit is contained in:
evilsocket 2018-02-19 14:36:24 +01:00
commit d95373bfa8
6 changed files with 22 additions and 21 deletions

View file

@ -118,7 +118,7 @@ func (w WiFiRecon) Author() string {
return "Gianluca Braga <matrix86@protonmail.com>" return "Gianluca Braga <matrix86@protonmail.com>"
} }
func (w *WiFiRecon) getRow(station *network.WiFiStation) []string { func (w *WiFiRecon) getRow(station *network.Station) []string {
sinceStarted := time.Since(w.Session.StartedAt) sinceStarted := time.Since(w.Session.StartedAt)
sinceFirstSeen := time.Since(station.FirstSeen) sinceFirstSeen := time.Since(station.FirstSeen)

View file

@ -4,7 +4,7 @@ import (
"github.com/evilsocket/bettercap-ng/network" "github.com/evilsocket/bettercap-ng/network"
) )
type ByRSSISorter []*network.WiFiStation type ByRSSISorter []*network.Station
func (a ByRSSISorter) Len() int { return len(a) } func (a ByRSSISorter) Len() int { return len(a) }
func (a ByRSSISorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByRSSISorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
@ -15,7 +15,7 @@ func (a ByRSSISorter) Less(i, j int) bool {
return a[i].RSSI > a[j].RSSI return a[i].RSSI > a[j].RSSI
} }
type ByChannelSorter []*network.WiFiStation type ByChannelSorter []*network.Station
func (a ByChannelSorter) Len() int { return len(a) } func (a ByChannelSorter) Len() int { return len(a) }
func (a ByChannelSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByChannelSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
@ -26,7 +26,7 @@ func (a ByChannelSorter) Less(i, j int) bool {
return a[i].Channel < a[j].Channel return a[i].Channel < a[j].Channel
} }
type ByEssidSorter []*network.WiFiStation type ByEssidSorter []*network.Station
func (a ByEssidSorter) Len() int { return len(a) } func (a ByEssidSorter) Len() int { return len(a) }
func (a ByEssidSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByEssidSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
@ -37,7 +37,7 @@ func (a ByEssidSorter) Less(i, j int) bool {
return a[i].ESSID() < a[j].ESSID() return a[i].ESSID() < a[j].ESSID()
} }
type ByWiFiSeenSorter []*network.WiFiStation type ByWiFiSeenSorter []*network.Station
func (a ByWiFiSeenSorter) Len() int { return len(a) } func (a ByWiFiSeenSorter) Len() int { return len(a) }
func (a ByWiFiSeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByWiFiSeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

View file

@ -10,6 +10,7 @@ import (
) )
type OnHostResolvedCallback func(e *Endpoint) type OnHostResolvedCallback func(e *Endpoint)
type Endpoint struct { type Endpoint struct {
Index int `json:"-"` Index int `json:"-"`
IP net.IP `json:"-"` IP net.IP `json:"-"`

View file

@ -5,13 +5,13 @@ import (
"time" "time"
) )
type StationNewCallback func(s *WiFiStation) type StationNewCallback func(s *Station)
type StationLostCallback func(s *WiFiStation) type StationLostCallback func(s *Station)
type WiFi struct { type WiFi struct {
sync.Mutex sync.Mutex
Interface *Endpoint Interface *Endpoint
Stations map[string]*WiFiStation Stations map[string]*Station
newCb StationNewCallback newCb StationNewCallback
lostCb StationLostCallback lostCb StationLostCallback
@ -20,17 +20,17 @@ type WiFi struct {
func NewWiFi(iface *Endpoint, newcb StationNewCallback, lostcb StationLostCallback) *WiFi { func NewWiFi(iface *Endpoint, newcb StationNewCallback, lostcb StationLostCallback) *WiFi {
return &WiFi{ return &WiFi{
Interface: iface, Interface: iface,
Stations: make(map[string]*WiFiStation), Stations: make(map[string]*Station),
newCb: newcb, newCb: newcb,
lostCb: lostcb, lostCb: lostcb,
} }
} }
func (w *WiFi) List() (list []*WiFiStation) { func (w *WiFi) List() (list []*Station) {
w.Lock() w.Lock()
defer w.Unlock() defer w.Unlock()
list = make([]*WiFiStation, 0) list = make([]*Station, 0)
for _, t := range w.Stations { for _, t := range w.Stations {
list = append(list, t) list = append(list, t)
} }
@ -49,7 +49,7 @@ func (w *WiFi) Remove(mac string) {
} }
} }
func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int, rssi int8) *WiFiStation { func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int, rssi int8) *Station {
w.Lock() w.Lock()
defer w.Unlock() defer w.Unlock()
@ -60,7 +60,7 @@ func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int, rssi int8) *Wi
return station return station
} }
newStation := NewWiFiStation(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 {
@ -71,6 +71,6 @@ func (w *WiFi) AddIfNew(ssid, mac string, isAp bool, channel int, rssi int8) *Wi
} }
func (w *WiFi) Clear() error { func (w *WiFi) Clear() error {
w.Stations = make(map[string]*WiFiStation) w.Stations = make(map[string]*Station)
return nil return nil
} }

View file

@ -1,6 +1,6 @@
package network package network
type WiFiStation struct { type Station struct {
*Endpoint *Endpoint
IsAP bool IsAP bool
Channel int Channel int
@ -10,8 +10,8 @@ type WiFiStation struct {
Encryption string Encryption string
} }
func NewWiFiStation(essid, bssid string, isAp bool, channel int, rssi int8) *WiFiStation { func NewStation(essid, bssid string, isAp bool, channel int, rssi int8) *Station {
return &WiFiStation{ return &Station{
Endpoint: NewEndpointNoResolve(MonitorModeAddress, bssid, essid, 0), Endpoint: NewEndpointNoResolve(MonitorModeAddress, bssid, essid, 0),
IsAP: isAp, IsAP: isAp,
Channel: channel, Channel: channel,
@ -19,10 +19,10 @@ func NewWiFiStation(essid, bssid string, isAp bool, channel int, rssi int8) *WiF
} }
} }
func (s WiFiStation) BSSID() string { func (s Station) BSSID() string {
return s.HwAddress return s.HwAddress
} }
func (s *WiFiStation) ESSID() string { func (s *Station) ESSID() string {
return s.Hostname return s.Hostname
} }

View file

@ -378,9 +378,9 @@ func (s *Session) Start() error {
s.Firewall = firewall.Make(s.Interface) s.Firewall = firewall.Make(s.Interface)
s.WiFi = network.NewWiFi(s.Interface, func(st *network.WiFiStation) { s.WiFi = network.NewWiFi(s.Interface, func(st *network.Station) {
s.Events.Add("wifi.station.new", st) s.Events.Add("wifi.station.new", st)
}, func(st *network.WiFiStation) { }, func(st *network.Station) {
s.Events.Add("wifi.station.lost", st) s.Events.Add("wifi.station.lost", st)
}) })