-
-
Save Djey1301/df39de937cf0258b562bd389458c352e to your computer and use it in GitHub Desktop.
Parse iw scan output
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
# iw wlan0 scan | sed -e 's#(on wlan# (on wlan#g' | awk -f scan.awk | |
#BEGIN { | |
# printf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n","MAC","SSID","freq","signal","sig%","WPA","WPA2","WEP","TKIP","CCMP"); | |
#} | |
NF > 0{ | |
if ($1 == "BSS") { | |
if( $2 ~ /^[a-z0-9:]{17}$/ ) { | |
if( e["MAC"] ){ | |
printf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n",e["MAC"],e["SSID"],e["freq"],e["sig"],e["sig%"],e["WPA"],e["WPA2"],e["WEP"],e["TKIP"],e["CCMP"]); | |
} | |
e["MAC"] = $2; | |
e["WPA"] = "n"; | |
e["WPA2"] = "n"; | |
e["WEP"] = "n"; | |
e["TKIP"] = "n"; | |
e["CCMP"] = "n"; | |
} | |
} | |
if ($1 == "SSID:") { | |
e["SSID"] = $2; | |
} | |
if ($1 == "freq:") { | |
e["freq"] = $NF; | |
} | |
if ($1 == "signal:") { | |
e["sig"] = $2 " " $3; | |
e["sig%"] = (60 - ((-$2) - 40)) * 100 / 60; | |
} | |
if ($1 == "WPA:") { | |
e["WPA"] = "y"; | |
} | |
if ($1 == "RSN:") { | |
e["WPA2"] = "y"; | |
} | |
if ($1 == "WEP:") { | |
e["WEP"] = "y"; | |
} | |
if ($4 == "CCMP" || $5 == "CCMP") { | |
e["CCMP"] = "y"; | |
} | |
if ($4 == "TKIP" || $5 == "TKIP") { | |
e["TKIP"] = "y"; | |
} | |
} | |
END { | |
printf("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s\n",e["MAC"],e["SSID"],e["freq"],e["sig"],e["sig%"],e["WPA"],e["WPA2"],e["WEP"],e["TKIP"],e["CCMP"]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment