Created
March 29, 2021 14:47
-
-
Save drygdryg/21b2045a9577738456131dce84a9e889 to your computer and use it in GitHub Desktop.
Extract info about a single access point from iw scan output
This file contains hidden or 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
#!/usr/bin/env python3 | |
import subprocess | |
import sys | |
import re | |
BSS_PATTERN = re.compile(r'BSS (\S+)( )?\(on \w+\)') | |
if __name__ == '__main__': | |
if len(sys.argv) != 3: | |
print(f"Usage: {sys.argv[0]} <interface> <bssid>") | |
exit(1) | |
interface = sys.argv[1] | |
bssid = sys.argv[2].lower() | |
cmd = 'iw dev {} scan'.format(interface) | |
proc = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT, encoding='utf-8', errors='ignore') | |
lines = proc.stdout.splitlines() | |
result = "" | |
current_bssid = "" | |
for line in lines: | |
match = re.match(BSS_PATTERN, line) | |
if match: | |
current_bssid = match.group(1) | |
if current_bssid == bssid: | |
result += line + '\n' | |
result = result[:-1] # Skip last newline | |
if result: | |
print(result) | |
else: | |
print("No results") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment