Skip to content

Instantly share code, notes, and snippets.

@kirkins
Created October 27, 2017 17:22
Show Gist options
  • Save kirkins/d1544b3b9d9d6bf910214dce0668fde3 to your computer and use it in GitHub Desktop.
Save kirkins/d1544b3b9d9d6bf910214dce0668fde3 to your computer and use it in GitHub Desktop.
Scan wifi without nmcli
#!/usr/bin/env bash
#
# Scan availible wifi networks
wifi=$(ifconfig -a | grep wl | cut -d' ' -f1)
ifconfig $wifi up
scan=$(iwlist $wifi scan)
essid=$(echo "$scan" | grep ESSID | cut -f2 -d":" | tr -d '"')
encryption=$(echo "$scan" | grep "Encryption key" | cut -f2 -d":")
bitrate=$(echo "$scan" | grep "Bit Rates" | cut -f2 -d":")
i=1
json=$(echo "["
while read -r ssid; do
echo "{ \"ssid\": \"$ssid\","
echo "\"security\": \""$(echo "$encryption" | sed "${i}q;d")"\","
echo "\"bitrate\": \""$(echo "$bitrate" | sed "${i}q;d")"\" },"
((i++))
done <<< "$essid"
echo "]"
)
echo $json | sed -z 's/\(.*\),/\1/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment