-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwlan.py
More file actions
31 lines (27 loc) · 1.02 KB
/
wlan.py
File metadata and controls
31 lines (27 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import subprocess
import re
from collections import defaultdict
def get_name_strength_map():
ret = defaultdict(set)
proc1 = subprocess.Popen(['sudo', 'iwlist', 'scan'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
proc2 = subprocess.Popen(['grep', 'ESSID\|Signal level'], stdin=proc1.stdout, stdout = subprocess.PIPE, stderr= subprocess.PIPE)
proc1.stdout.close()
quality = 0
signal_level = -1
while True:
line = proc2.stdout.readline()
if not line:
break
line = line.decode("utf-8").strip()
match = re.search('ESSID:"(.*)"', line)
if match is not None:
# if match.group(1) is not "":
ret[match.group(1)].add((quality, signal_level))
continue
match = re.search('Quality=(.*) Signal level=(.*) dBm', line)
if match is not None:
quality = match.group(1).strip()
signal_level = match.group(2).strip()
return ret
if __name__ == "__main__":
print(get_name_strength_map())