From 4e82a4356a469adba9580d6472b3dc04ce012b4b Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sun, 27 Jan 2019 15:01:44 +0100 Subject: [PATCH] fix: sorting WPS fields by name for wifi.show.wps command --- modules/wifi_show.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/wifi_show.go b/modules/wifi_show.go index 9132abac..da2f96d9 100644 --- a/modules/wifi_show.go +++ b/modules/wifi_show.go @@ -296,18 +296,18 @@ func (w *WiFiModule) Show() (err error) { } func (w *WiFiModule) ShowWPS(bssid string) (err error) { - toShow := []*network.AccessPoint{} + toShow := []*network.Station{} if bssid == network.BroadcastMac { for _, station := range w.Session.WiFi.List() { if station.HasWPS() { - toShow = append(toShow, station) + toShow = append(toShow, station.Station) } } } else { if station, found := w.Session.WiFi.Get(bssid); found { if station.HasWPS() { - toShow = append(toShow, station) + toShow = append(toShow, station.Station) } } } @@ -316,6 +316,7 @@ func (w *WiFiModule) ShowWPS(bssid string) (err error) { return fmt.Errorf("no WPS enabled access points matched the criteria") } + sort.Sort(ByBssidSorter(toShow)) for _, station := range toShow { ssid := station.ESSID() if ssid == "" { @@ -324,8 +325,14 @@ func (w *WiFiModule) ShowWPS(bssid string) (err error) { fmt.Println() fmt.Printf("* %s (%s ch:%d):\n", tui.Bold(ssid), tui.Dim(station.BSSID()), station.Channel()) - for name, value := range station.WPS { - fmt.Printf(" %s: %s\n", name, tui.Yellow(value)) + keys := []string{} + for name, _ := range station.WPS { + keys = append(keys, name) + } + sort.Strings(keys) + + for _, name := range keys { + fmt.Printf(" %s: %s\n", name, tui.Yellow(station.WPS[name])) } }