Skip to content

Instantly share code, notes, and snippets.

@petermaloney
Created May 19, 2017 13:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petermaloney/3f028462143d2b3eeef0df8d63eff733 to your computer and use it in GitHub Desktop.
Save petermaloney/3f028462143d2b3eeef0df8d63eff733 to your computer and use it in GitHub Desktop.
parse iwlist scan output for specific SSID
getssid() {
local ssid="$1"
awk -v ssid="$ssid" '
BEGIN {
matching_lines="";
lines="";
found=0;
found_ssid=""
};
$0 ~ /^BSS/ {
if ( found_ssid ~ ssid ) {
matching_lines=lines
}
found=1;
lines="";
found_ssid=""
};
found {lines = lines "\n" $0};
/SSID/ {found_ssid=$0};
END {
if ( found_ssid ~ ssid ) {
matching_lines=lines
}
print matching_lines;
}'
}
# example usage
iwlist "$interface" scan | getssid TMWLAN
iwlist "$interface" scan | getssid 'x00'
# this works, but...
iwlist "$interface" scan | getssid 'x00'
# these don't work.... not sure how to get the full SSID here
iwlist "$interface" scan | getssid '\\x00\\x00\\x00\\x00\\x00\\x00'
iwlist "$interface" scan | cat sample | getssid '\x00\x00\x00\x00\x00\x00'
wget -O- https://gist.github.com/anonymous/507a7ffb2754c0d42a1a7fcac4bb3d41/raw/daba029437ffa1cd4df6851157e945a17f0c0b15/gistfile1.txt | getssid TMWLAN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment