Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CLI option to specify the pcap flie #46

Merged
merged 2 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Namely you want to find a USB adapter with one of the following chipsets: Athero
brew cask install wireshark-chmodbpf
```

You need to dissociate from any AP before initiating the scanning:
```
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z
```

### Linux [tshark](https://www.wireshark.org/docs/man-pages/tshark.html)
```
sudo apt-get install tshark
Expand Down
76 changes: 42 additions & 34 deletions howmanypeoplearearound/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,21 @@ def fileToMacSet(path):
@click.option('--port', default=8001, help='port to use when serving analysis')
@click.option('--sort', help='sort cellphone data by distance (rssi)', is_flag=True)
@click.option('--targetmacs', help='read a file that contains target MAC addresses', default='')
def main(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out, allmacaddresses, nocorrection, loop, analyze, port, sort, targetmacs):
@click.option('-f', '--pcap', help='read a pcap file instead of capturing')
def main(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out, allmacaddresses, nocorrection, loop, analyze, port, sort, targetmacs, pcap):
if analyze != '':
analyze_file(analyze, port)
return
if loop:
while True:
adapter = scan(adapter, scantime, verbose, dictionary, number,
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs)
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs, pcap)
else:
scan(adapter, scantime, verbose, dictionary, number,
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs)
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs, pcap)


def scan(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs):
def scan(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs, pcap):
"""Monitor wifi signals to count the number of people around you"""

# print("OS: " + os.name)
Expand Down Expand Up @@ -117,39 +118,45 @@ def scan(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out,
if number:
verbose = False

if len(adapter) == 0:
if os.name == 'nt':
print('You must specify the adapter with -a ADAPTER')
print('Choose from the following: ' +
', '.join(netifaces.interfaces()))
sys.exit(1)
title = 'Please choose the adapter you want to use: '
adapter, index = pick(netifaces.interfaces(), title)

print("Using %s adapter and scanning for %s seconds..." %
(adapter, scantime))

if not number:
# Start timer
t1 = threading.Thread(target=showTimer, args=(scantime,))
t1.daemon = True
t1.start()

# Scan with tshark
command = [tshark, '-I', '-i', adapter, '-a',
'duration:' + scantime, '-w', '/tmp/tshark-temp']
if verbose:
print(' '.join(command))
run_tshark = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, nothing = run_tshark.communicate()
if not number:
t1.join()
if not pcap:
if len(adapter) == 0:
if os.name == 'nt':
print('You must specify the adapter with -a ADAPTER')
print('Choose from the following: ' +
', '.join(netifaces.interfaces()))
sys.exit(1)
title = 'Please choose the adapter you want to use: '
adapter, index = pick(netifaces.interfaces(), title)

print("Using %s adapter and scanning for %s seconds..." %
(adapter, scantime))

if not number:
# Start timer
t1 = threading.Thread(target=showTimer, args=(scantime,))
t1.daemon = True
t1.start()

dump_file = '/tmp/tshark-temp'
# Scan with tshark
command = [tshark, '-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()


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

# Read tshark output
command = [
tshark, '-r',
'/tmp/tshark-temp', '-T',
dump_file, '-T',
'fields', '-e',
'wlan.sa', '-e',
'wlan.bssid', '-e',
Expand Down Expand Up @@ -259,7 +266,8 @@ 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))
os.remove('/tmp/tshark-temp')
if not pcap:
os.remove(dump_file)
return adapter


Expand Down
8 changes: 5 additions & 3 deletions howmanypeoplearearound/oui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from urllib.request import urlopen
from urllib.request import Request
try: #python3
from urllib.request import urlopen
except: #python2
from urllib2 import urlopen


def load_dictionary(file):
Expand All @@ -17,6 +19,6 @@ def load_dictionary(file):
def download_oui(to_file):
uri = 'http://standards-oui.ieee.org/oui/oui.txt'
print("Trying to download current version of oui.txt from [%s] to file [%s]" % (uri, to_file))
oui_data = urlopen(Request(uri), timeout=10).read()
oui_data = urlopen(uri, timeout=10).read()
with open(to_file, 'wb') as oui_file:
oui_file.write(oui_data)