Skip to content

Commit

Permalink
Added CLI option to specify the pcap flie
Browse files Browse the repository at this point in the history
  • Loading branch information
asutoshpalai committed Jan 20, 2019
1 parent 3df1d83 commit 34933da
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ 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 @@ -71,20 +71,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, 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, 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, number,
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs)
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs, pcap)
else:
scan(adapter, scantime, verbose, number,
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs)
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs, pcap)


def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs):
def scan(adapter, scantime, verbose, 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 All @@ -106,39 +107,45 @@ def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddre
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()))
return
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()))
return
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 @@ -248,7 +255,8 @@ def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddre
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

0 comments on commit 34933da

Please sign in to comment.