Created
October 27, 2017 17:22
-
-
Save kirkins/d1544b3b9d9d6bf910214dce0668fde3 to your computer and use it in GitHub Desktop.
Scan wifi without nmcli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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