Skip to content

Instantly share code, notes, and snippets.

@Djey1301
Forked from elecnix/scan.awk
Created September 29, 2016 12:53
Show Gist options
  • Save Djey1301/df39de937cf0258b562bd389458c352e to your computer and use it in GitHub Desktop.
Save Djey1301/df39de937cf0258b562bd389458c352e to your computer and use it in GitHub Desktop.
Parse iw scan output
# 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