Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dinther's full-sized avatar

Paul van Dinther dinther

  • Dinther Product Design
  • Auckland, New Zealand
  • 19:04 (UTC +12:00)
View GitHub Profile
@dinther
dinther / listwifi.md
Created December 12, 2022 13:42
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.