mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
8d2f0af82b
commit
d95373bfa8
6 changed files with 22 additions and 21 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -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] }
|
||||||
|
|
|
@ -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:"-"`
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue