Debian Codegraph @

modules/wifi/wifi_show_sort.go

raw symbols SCIP
1 package wifi
2
3 import (
4 "github.com/bettercap/bettercap/network"
5 "github.com/bettercap/bettercap/session"
6 )
7
8 type ByRSSISorter []*network.Station
9
10 func (a ByRSSISorter) Len() int { return len(a) }
11 func (a ByRSSISorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
12 func (a ByRSSISorter) Less(i, j int) bool {
13 if a[i].RSSI == a[j].RSSI {
14 return a[i].HwAddress < a[j].HwAddress
15 }
16 return a[i].RSSI > a[j].RSSI
17 }
18
19 type ByChannelSorter []*network.Station
20
21 func (a ByChannelSorter) Len() int { return len(a) }
22 func (a ByChannelSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
23 func (a ByChannelSorter) Less(i, j int) bool {
24 return a[i].Frequency < a[j].Frequency
25 }
26
27 type ByEncryptionSorter []*network.Station
28
29 func (a ByEncryptionSorter) Len() int { return len(a) }
30 func (a ByEncryptionSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
31 func (a ByEncryptionSorter) Less(i, j int) bool {
32 if a[i].Encryption == a[j].Encryption {
33 return a[i].HwAddress < a[j].HwAddress
34 }
35 return a[i].Encryption < a[j].Encryption
36 }
37
38 type ByBssidSorter []*network.Station
39
40 func (a ByBssidSorter) Len() int { return len(a) }
41 func (a ByBssidSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
42 func (a ByBssidSorter) Less(i, j int) bool {
43 return a[i].BSSID() < a[j].BSSID()
44 }
45
46 type ByEssidSorter []*network.Station
47
48 func (a ByEssidSorter) Len() int { return len(a) }
49 func (a ByEssidSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
50 func (a ByEssidSorter) Less(i, j int) bool {
51 if a[i].ESSID() == a[j].ESSID() {
52 return a[i].HwAddress < a[j].HwAddress
53 }
54 return a[i].ESSID() < a[j].ESSID()
55 }
56
57 type ByWiFiSeenSorter []*network.Station
58
59 func (a ByWiFiSeenSorter) Len() int { return len(a) }
60 func (a ByWiFiSeenSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
61 func (a ByWiFiSeenSorter) Less(i, j int) bool {
62 return a[i].LastSeen.Before(a[j].LastSeen)
63 }
64
65 type ByWiFiSentSorter []*network.Station
66
67 func (a ByWiFiSentSorter) Len() int { return len(a) }
68 func (a ByWiFiSentSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
69 func (a ByWiFiSentSorter) Less(i, j int) bool {
70 return a[i].Sent < a[j].Sent
71 }
72
73 type ByWiFiRcvdSorter []*network.Station
74
75 func (a ByWiFiRcvdSorter) Len() int { return len(a) }
76 func (a ByWiFiRcvdSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
77 func (a ByWiFiRcvdSorter) Less(i, j int) bool {
78 return a[i].Received < a[j].Received
79 }
80
81 type ByClientsSorter []*network.Station
82
83 func (a ByClientsSorter) Len() int { return len(a) }
84 func (a ByClientsSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
85 func (a ByClientsSorter) Less(i, j int) bool {
86 left := 0
87 right := 0
88
89 if ap, found := session.I.WiFi.Get(a[i].HwAddress); found {
90 left = ap.NumClients()
91 }
92 if ap, found := session.I.WiFi.Get(a[j].HwAddress); found {
93 right = ap.NumClients()
94 }
95
96 if left == right {
97 return a[i].HwAddress < a[j].HwAddress
98 }
99 return left < right
100 }