Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions howmanypeoplearearound/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import subprocess
import json
import time
import tempfile

import netifaces
import click
Expand All @@ -18,6 +19,7 @@
from pick import pick
import curses


def which(program):
"""Determines whether program exists
"""
Expand Down Expand Up @@ -143,20 +145,28 @@ def scan(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out,
t1.daemon = True
t1.start()

dump_file = '/tmp/tshark-temp'
tmpdir = tempfile.mkdtemp()
dump_file = os.path.join(tmpdir, 'tshark-temp')

# Scan with tshark
command = [tshark, '-I', '-i', adapter, '-a',
# EP, 20240817: -Q flags silences non-essential output that we don't use anyway,
# so anything on stderr is actually an error
command = [tshark, '-Q', '-I', '-i', adapter, '-a',
'duration:' + scantime, '-w', dump_file]
if verbose:
print(' '.join(command))
run_tshark = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, nothing = run_tshark.communicate()
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = run_tshark.communicate()

if stderr != b"":
print("Warning: error when running tshark:\n")
print(stderr.decode('utf8').strip())

if not number:
t1.join()
else:
tmpdir = None
dump_file = pcap

# Read tshark output
Expand All @@ -171,15 +181,20 @@ def scan(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out,
if verbose:
print(' '.join(command))
run_tshark = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, nothing = run_tshark.communicate()
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, stderr = run_tshark.communicate()

if stderr != b"":
print("Warning: error parsing tshark output")
print(stderr.decode('utf8').strip())

# read target MAC address
targetmacset = set()
if targetmacs != '':
targetmacset = fileToMacSet(targetmacs)

foundMacs = {}

for line in output.decode('utf-8').split('\n'):
if verbose:
print(line)
Expand Down Expand Up @@ -277,8 +292,9 @@ def scan(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out,
f.write(json.dumps(data_dump) + "\n")
if verbose:
print("Wrote %d records to %s" % (len(cellphone_people), out))
if not pcap:
if tmpdir is not None:
os.remove(dump_file)
os.rmdir(tmpdir)
return adapter


Expand Down