Commit a1695a1f authored by root's avatar root

Remove iwlist.py, we don't use it.

parent 317984f1
import re
import subprocess
cellNumberRe = re.compile(r"^Cell\s+(?P<cellnumber>.+)\s+-\s+Address:\s(?P<mac>.+)$")
regexps = [
re.compile(r"^ESSID:\"(?P<essid>.*)\"$"),
re.compile(r"^Protocol:(?P<protocol>.+)$"),
re.compile(r"^Mode:(?P<mode>.+)$"),
re.compile(r"^Frequency:(?P<frequency>[\d.]+) (?P<frequency_units>.+) \(Channel (?P<channel>\d+)\)$"),
re.compile(r"^Encryption key:(?P<encryption>.+)$"),
re.compile(r"^Quality=(?P<signal_quality>\d+)/(?P<signal_total>\d+)\s+Signal level=(?P<signal_level_dBm>.+) d.+$"),
re.compile(r"^Signal level=(?P<signal_quality>\d+)/(?P<signal_total>\d+).*$"),
]
# Detect encryption type
wpaRe = re.compile(r"IE:\ WPA\ Version\ 1$")
wpa2Re = re.compile(r"IE:\ IEEE\ 802\.11i/WPA2\ Version\ 1$")
# Runs the comnmand to scan the list of networks.
# Must run as super user.
# Does not specify a particular device, so will scan all network devices.
def scan(interface='wlan0'):
cmd = ["iwlist", interface, "scan"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
points = proc.stdout.read().decode('utf-8')
return points
# Parses the response from the command "iwlist scan"
def parse(content):
cells = []
lines = content.split('\n')
for line in lines:
line = line.strip()
cellNumber = cellNumberRe.search(line)
if cellNumber is not None:
cells.append(cellNumber.groupdict())
continue
wpa = wpaRe.search(line)
if wpa is not None :
cells[-1].update({'encryption':'wpa'})
wpa2 = wpa2Re.search(line)
if wpa2 is not None :
cells[-1].update({'encryption':'wpa2'})
for expression in regexps:
result = expression.search(line)
if result is not None:
if 'encryption' in result.groupdict() :
if result.groupdict()['encryption'] == 'on' :
cells[-1].update({'encryption': 'wep'})
else :
cells[-1].update({'encryption': 'off'})
else :
cells[-1].update(result.groupdict())
continue
return cells
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment