mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 05:23:19 -07:00
new: added wifi.show clients and encryption sorting
This commit is contained in:
parent
573cb17735
commit
58738b7723
3 changed files with 43 additions and 36 deletions
|
@ -2,7 +2,6 @@ package modules
|
|||
|
||||
import (
|
||||
"github.com/bettercap/bettercap/network"
|
||||
"github.com/bettercap/bettercap/packets"
|
||||
"github.com/bettercap/bettercap/session"
|
||||
)
|
||||
|
||||
|
@ -11,7 +10,10 @@ type ByRSSISorter []*network.Station
|
|||
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) Less(i, j int) bool {
|
||||
return a[i].RSSI < a[j].RSSI
|
||||
if a[i].RSSI == a[j].RSSI {
|
||||
return a[i].HwAddress < a[j].HwAddress
|
||||
}
|
||||
return a[i].RSSI > a[j].RSSI
|
||||
}
|
||||
|
||||
type ByChannelSorter []*network.Station
|
||||
|
@ -22,6 +24,17 @@ func (a ByChannelSorter) Less(i, j int) bool {
|
|||
return a[i].Frequency < a[j].Frequency
|
||||
}
|
||||
|
||||
type ByEncryptionSorter []*network.Station
|
||||
|
||||
func (a ByEncryptionSorter) Len() int { return len(a) }
|
||||
func (a ByEncryptionSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByEncryptionSorter) Less(i, j int) bool {
|
||||
if a[i].Encryption == a[j].Encryption {
|
||||
return a[i].HwAddress < a[j].HwAddress
|
||||
}
|
||||
return a[i].Encryption < a[j].Encryption
|
||||
}
|
||||
|
||||
type ByBssidSorter []*network.Station
|
||||
|
||||
func (a ByBssidSorter) Len() int { return len(a) }
|
||||
|
@ -54,22 +67,7 @@ type ByWiFiSentSorter []*network.Station
|
|||
func (a ByWiFiSentSorter) Len() int { return len(a) }
|
||||
func (a ByWiFiSentSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByWiFiSentSorter) Less(i, j int) bool {
|
||||
session.I.Queue.Lock()
|
||||
defer session.I.Queue.Unlock()
|
||||
|
||||
var found bool = false
|
||||
var aTraffic *packets.Traffic = nil
|
||||
var bTraffic *packets.Traffic = nil
|
||||
|
||||
if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; !found {
|
||||
aTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; !found {
|
||||
bTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
return bTraffic.Sent > aTraffic.Sent
|
||||
return a[i].Sent < a[j].Sent
|
||||
}
|
||||
|
||||
type ByWiFiRcvdSorter []*network.Station
|
||||
|
@ -77,20 +75,26 @@ type ByWiFiRcvdSorter []*network.Station
|
|||
func (a ByWiFiRcvdSorter) Len() int { return len(a) }
|
||||
func (a ByWiFiRcvdSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByWiFiRcvdSorter) Less(i, j int) bool {
|
||||
session.I.Queue.Lock()
|
||||
defer session.I.Queue.Unlock()
|
||||
|
||||
var found bool = false
|
||||
var aTraffic *packets.Traffic = nil
|
||||
var bTraffic *packets.Traffic = nil
|
||||
|
||||
if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; !found {
|
||||
aTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; !found {
|
||||
bTraffic = &packets.Traffic{}
|
||||
}
|
||||
|
||||
return bTraffic.Received > aTraffic.Received
|
||||
return a[i].Received < a[j].Received
|
||||
}
|
||||
|
||||
type ByClientsSorter []*network.Station
|
||||
|
||||
func (a ByClientsSorter) Len() int { return len(a) }
|
||||
func (a ByClientsSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByClientsSorter) Less(i, j int) bool {
|
||||
left := 0
|
||||
right := 0
|
||||
|
||||
if ap, found := session.I.WiFi.Get(a[i].HwAddress); found {
|
||||
left = ap.NumClients()
|
||||
}
|
||||
if ap, found := session.I.WiFi.Get(a[j].HwAddress); found {
|
||||
right = ap.NumClients()
|
||||
}
|
||||
|
||||
if left == right {
|
||||
return a[i].HwAddress < a[j].HwAddress
|
||||
}
|
||||
return left < right
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue