From b80bd4e1e24fdf7f824af8b9f28bf41d24c3f43d Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sat, 17 Feb 2018 02:52:43 +0100 Subject: [PATCH] misc: small fix or general refactoring i did not bother commenting --- modules/wifi_recon.go | 30 ------------------------------ modules/wifi_recon_sort.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 modules/wifi_recon_sort.go diff --git a/modules/wifi_recon.go b/modules/wifi_recon.go index 2f0e6d2b..b2b1bd32 100644 --- a/modules/wifi_recon.go +++ b/modules/wifi_recon.go @@ -184,36 +184,6 @@ func mhz2chan(freq int) int { return 0 } -type ByChannelSorter []*WiFiStation - -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 { - if a[i].Channel == a[j].Channel { - return a[i].HwAddress < a[j].HwAddress - } - return a[i].Channel < a[j].Channel -} - -type ByEssidSorter []*WiFiStation - -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 []*WiFiStation - -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.After(a[j].LastSeen) -} - func (w *WiFiRecon) showTable(header []string, rows [][]string) { fmt.Println() table := tablewriter.NewWriter(os.Stdout) diff --git a/modules/wifi_recon_sort.go b/modules/wifi_recon_sort.go new file mode 100644 index 00000000..aba6a0fd --- /dev/null +++ b/modules/wifi_recon_sort.go @@ -0,0 +1,31 @@ +package modules + +type ByChannelSorter []*WiFiStation + +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 { + if a[i].Channel == a[j].Channel { + return a[i].HwAddress < a[j].HwAddress + } + return a[i].Channel < a[j].Channel +} + +type ByEssidSorter []*WiFiStation + +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 []*WiFiStation + +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.After(a[j].LastSeen) +}