/
wifi_show_sort.go
100 lines (79 loc) · 2.81 KB
/
wifi_show_sort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package wifi
import (
"github.com/bettercap/bettercap/network"
"github.com/bettercap/bettercap/session"
)
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 {
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
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) 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) }
func (a ByBssidSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByBssidSorter) Less(i, j int) bool {
return a[i].BSSID() < a[j].BSSID()
}
type ByEssidSorter []*network.Station
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) Less(i, j int) bool {
if a[i].ESSID() == a[j].ESSID() {
return a[i].HwAddress < a[j].HwAddress
}
return a[i].ESSID() < a[j].ESSID()
}
type ByWiFiSeenSorter []*network.Station
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) Less(i, j int) bool {
return a[i].LastSeen.Before(a[j].LastSeen)
}
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 {
return a[i].Sent < a[j].Sent
}
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 {
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
}