From 7861c248c2d05c56820b3f0d916e69629bb38f73 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sat, 17 Aug 2024 09:53:52 +0100 Subject: [PATCH] More robust lookup for Linux wireless name --- modules/status/network.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/modules/status/network.go b/modules/status/network.go index 9f8e8f90..7019fc06 100644 --- a/modules/status/network.go +++ b/modules/status/network.go @@ -1,6 +1,7 @@ package status import ( + "errors" "log" "os" "os/exec" @@ -32,27 +33,20 @@ func (n *network) Destroy() { func (n *network) wirelessName() (string, error) { net := "" - iw, _ := exec.LookPath("iw") + iw, _ := exec.LookPath("iwconfig") if iw == "" { - iw, _ = exec.LookPath("/usr/sbin/iw") + iw, _ = exec.LookPath("/usr/sbin/iwconfig") } if iw != "" { - out, err := exec.Command("bash", []string{"-c", iw + " dev | grep Interface | cut -d \" \" -f2"}...).Output() + out, err := exec.Command("bash", []string{"-c", iw + " | grep ESSID | cut -d '\"' -f2"}...).Output() if err != nil { - log.Println("Error running iw", err) + log.Println("Error running iwconfig", err) return "", err } - dev := strings.TrimSpace(string(out)) - if dev == "" { - return "", nil + if strings.Contains(string(out), "ESSID") { + return "", errors.New("no network connected") } - - out, err = exec.Command("bash", []string{"-c", iw + " dev " + dev + " info | grep ssid | sed 's\\ssid\\\\g'"}...).Output() - if err != nil { - log.Println("Error running iw", err) - return "", err - } - net = string(out) + net = strings.TrimSpace(string(out)) } else { out, err := exec.Command("bash", []string{"-c", "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | awk -F' SSID: ' '/ SSID: / {print $2}'"}...).Output() if err != nil {