blob: b1e9b3dfbe7a55c02c7307b9153aa8c0aca168c4 [file] [log] [blame]
"""tcpdump: helper module that gathers wireless network MCS using tcpdump."""
import multiprocessing
import os
import re
import subprocess
def MCSBackground(tcpdump, out):
"""Continually extract wireless MCS from `tcpdump` output.
If tcpdump is actively capturing packets, this function will not return as
long as tcpdump is running. You probably want to run it in a background
activity using multiprocessing.
tcpdump: a tcpdump process that's writing text output with Radiotap headers
to its stdout stream.
out: Python file-like object to write MCS information to.
mcsre = re.compile(r'MCS (\d+)')
x = 0
for row in iter(tcpdump.stdout.readline, b''):
x += 1
match =
if match:
mcs = int(
out.write('{:02} '.format(mcs))
out.write(' . ')
if x % 25 == 0:
def MCS(bssid, interface, report_dir=''):
"""Runs tcpdump in the background to gather wireless MCS."""
print 'Please enter password for `sudo` if prompted.'['sudo', '-v'])
out = open(os.path.join(report_dir, 'mcs'), 'w+b')
err = open(os.path.join(report_dir, 'mcserr'), 'w+b')
filt = ('(not subtype beacon and not subtype ack) and '
'(wlan addr1 {0} or wlan addr2 {0} or wlan addr3 {0})'.format(
bssid, bssid, bssid))
sudo_tcpdump = subprocess.Popen(['sudo', 'tcpdump', '-Z', os.getlogin(),
'-Ilnei', interface, filt],
proc = multiprocessing.Process(target=MCSBackground,
args=(sudo_tcpdump, out))
return sudo_tcpdump, out, err