Skip to content

Instantly share code, notes, and snippets.

@dinther
Created December 12, 2022 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dinther/b4edd6611465a4248b48ad5e472ca722 to your computer and use it in GitHub Desktop.
Save dinther/b4edd6611465a4248b48ad5e472ca722 to your computer and use it in GitHub Desktop.
List wifi networks in JSON format.

If you need a list of wifi networks for your application then maybe this is useful for you. This solution makes use of the wpa_cli and then uses awk to format it.

sudo wpa_cli -i wlan0 scan 1>/dev/null; sleep 1; sudo wpa_cli -i wlan0 scan_results | awk 'BEGIN{ORS="";  print "["}; NR>1 {ORS=","; print "{\"signal\":"$3",\"ssid\":\""$5"\"}" }; END{ORS=""; print "]"}'

This command can be used in a shell. Either from your app or command line. The result goes to stdout you can either redirect it to a file or work with it directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment