Skip to content

Instantly share code, notes, and snippets.

@jaimet
Forked from elecnix/scan.awk
Created September 21, 2024 16:13
Show Gist options
  • Save jaimet/24f7b5bc8d8f92a4c65a500648a32efb to your computer and use it in GitHub Desktop.
Save jaimet/24f7b5bc8d8f92a4c65a500648a32efb 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
$1 == "BSS" {
MAC = $2
print $2
e = wifi[MAC]
e["enc"] = "Open"
}
$1 == "SSID:" {
e = wifi[MAC]
e["SSID"] = $2
}
$1 == "freq:" {
e = wifi[MAC]
e["freq"] = $NF
}
$1 == "signal:" {
e = wifi[MAC]
e["sig"] = $2 " " $3
}
$1 == "WPA:" {
e = wifi[MAC]
e["enc"] = "WPA"
}
$1 == "WEP:" {
e = wifi[MAC]
e["enc"] = "WEP"
}
END {
printf "%s\t\t%s\t%s\t\t%s\n","SSID","Frequency","Signal","Encryption"
for (w in wifi) {
e = wifi[w]
printf "%s\t\t%s\t\t%s\t%s\n",e["SSID"],e["freq"],e["sig"],e["enc"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment