3

I would like to get a list of the wireless networks available inside a Go program running under Linux OS. It's pretty easy to get this information from a Linux command line with iwlist but I really want to have it done natively in Go. Any ideas of which package should be used? Thank you.

  • 1
    https://github.com/skycoin/skycoin/blob/master/src/aether/wifi/wifi.go here is an implementation for the same activity which you can checkout. – ritesh Jul 18 '16 at 03:59
  • Hi Ritesh. Thanks for that. I found this one before but it's still using Linux commands to get the list of wireless networks. I might have to use OS-specific commands and handle the output to get the info I need. I'll keep trying!! ;) – Ulysses Figtree Jul 18 '16 at 17:51

1 Answers1

1

I was able to get the information by executing a Linux command. Here's the piece of code:

    iwlistCmd := exec.Command("iwlist", iface, "scan")
    iwlistCmdOut, err := iwlistCmd.Output()
    if err != nil {
        fmt.Println(err, "Error when getting the interface information.")
    } else {
        fmt.Println(string(iwlistCmdOut))
    }

The output is a huge list of information and works in Linux only. As a next stel I have to find a way to extract the info I need which is the ESSID probably with strings.split package/function.