Created
January 27, 2023 08:07
-
-
Save shriyanss/914cbcd27428c668be03406b38c76de0 to your computer and use it in GitHub Desktop.
Export output of iwlist as CSV format
This file contains 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
#!/bin/bash | |
readonly TMPSCAN=/tmp/scan | |
readonly NETWORKS=/tmp/networks | |
readonly NIC=wlan0 | |
scan () { | |
rm -f $NETWORKS | |
sudo iwlist $NIC scan > $TMPSCAN | |
ssids=($(cat $TMPSCAN | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')) | |
len=${#ssids[@]} | |
for ssid in ${ssids[@]} | |
do | |
cell=$(sed -n "/$ssid/,/Cell\ [0-9]/p" $TMPSCAN) | |
# array (chan enc essid) | |
cv=($(echo "$cell" | grep -E -o '(Channel:.+)|(Encryption.+)|(ESSID:.+)|(Frequency:[0-9\.]+)|(Quality=[0-9/]+)|(level=[0-9\-]+)' | sed 's/.*://')) | |
# echo ${cv[*]} | |
chan=${cv[0]} | |
enc=${cv[1]} | |
essid=${cv[@]:2} | |
quality=${cv[2]} | |
signal_level=${cv[3]} | |
# echo $signal_level | |
# echo $(echo $essid | grep -o -E "\".+\"" ) | |
#echo $enc | |
# echo ${quality//Quality=/} | |
# echo "$cell" | |
if [[ $(echo $essid | grep -o -E "(on|off)" ) == "on" ]]; then | |
if [[ "$cell" == *WPA[0-9]\ Version* ]]; then | |
enc_type=wpa | |
else | |
enc_type=wep | |
fi | |
fi | |
if [[ $(echo $essid | grep -o -E "\".+\"" ) == '""' ]]; then | |
essid="<hidden>" | |
fi | |
timestamp=$(date -u) | |
echo $ssid","$(echo $essid | grep -o -E "\".+\"" )","$chan","${quality//Quality=/}","${signal_level//level=/}","$enc","$timestamp","$(echo $essid | grep -o -E "(on|off)" )","$enc_type >> $NETWORKS | |
done | |
} | |
scan | |
# ssid,essid,channel,quality,signal_level,frequency,timestamp,encryption_status,encryption_type | |
cat $NETWORKS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment