Skip to content

Commit 6b2790a

Browse files
rawmindschollz
authored andcommitted
Added possibility specify oui file with flag (#42)
* dynamic oui.txt file support * use exit(1) instead of silent return * use exit(1) instead of silent return
1 parent 3df1d83 commit 6b2790a

File tree

4 files changed

+45
-23447
lines changed

4 files changed

+45
-23447
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ ENV/
8989

9090
# Rope project settings
9191
.ropeproject
92+
93+
# Pycharm
94+
.idea

howmanypeoplearearound/__main__.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import threading
22
import sys
33
import os
4+
import os.path
45
import platform
56
import subprocess
67
import json
@@ -9,7 +10,7 @@
910
import netifaces
1011
import click
1112

12-
from howmanypeoplearearound.oui import oui
13+
from howmanypeoplearearound.oui import load_dictionary, download_oui
1314
from howmanypeoplearearound.analysis import analyze_file
1415
from howmanypeoplearearound.colors import *
1516

@@ -61,6 +62,7 @@ def fileToMacSet(path):
6162
@click.option('-z', '--analyze', default='', help='analyze file')
6263
@click.option('-s', '--scantime', default='60', help='time in seconds to scan')
6364
@click.option('-o', '--out', default='', help='output cellphone data to file')
65+
@click.option('-d', '--dictionary', default='oui.txt', help='OUI dictionary')
6466
@click.option('-v', '--verbose', help='verbose mode', is_flag=True)
6567
@click.option('--number', help='just print the number', is_flag=True)
6668
@click.option('-j', '--jsonprint', help='print JSON of cellphone data', is_flag=True)
@@ -71,25 +73,34 @@ def fileToMacSet(path):
7173
@click.option('--port', default=8001, help='port to use when serving analysis')
7274
@click.option('--sort', help='sort cellphone data by distance (rssi)', is_flag=True)
7375
@click.option('--targetmacs', help='read a file that contains target MAC addresses', default='')
74-
def main(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddresses, nocorrection, loop, analyze, port, sort, targetmacs):
76+
def main(adapter, scantime, verbose, dictionary, number, nearby, jsonprint, out, allmacaddresses, nocorrection, loop, analyze, port, sort, targetmacs):
7577
if analyze != '':
7678
analyze_file(analyze, port)
7779
return
7880
if loop:
7981
while True:
80-
adapter = scan(adapter, scantime, verbose, number,
82+
adapter = scan(adapter, scantime, verbose, dictionary, number,
8183
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs)
8284
else:
83-
scan(adapter, scantime, verbose, number,
85+
scan(adapter, scantime, verbose, dictionary, number,
8486
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs)
8587

8688

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

9092
# print("OS: " + os.name)
9193
# print("Platform: " + platform.system())
9294

95+
if (not os.path.isfile(dictionary)) or (not os.access(dictionary, os.R_OK)):
96+
download_oui(dictionary)
97+
98+
oui = load_dictionary(dictionary)
99+
100+
if not oui:
101+
print('couldn\'t load [%s]' % dictionary)
102+
sys.exit(1)
103+
93104
try:
94105
tshark = which("tshark")
95106
except:
@@ -99,7 +110,7 @@ def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddre
99110
print('wireshark not found, install using: \n\tbrew install wireshark')
100111
print(
101112
'you may also need to execute: \n\tbrew cask install wireshark-chmodbpf')
102-
return
113+
sys.exit(1)
103114

104115
if jsonprint:
105116
number = True
@@ -111,7 +122,7 @@ def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddre
111122
print('You must specify the adapter with -a ADAPTER')
112123
print('Choose from the following: ' +
113124
', '.join(netifaces.interfaces()))
114-
return
125+
sys.exit(1)
115126
title = 'Please choose the adapter you want to use: '
116127
adapter, index = pick(netifaces.interfaces(), title)
117128

@@ -177,7 +188,7 @@ def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddre
177188

178189
if not foundMacs:
179190
print("Found no signals, are you sure %s supports monitor mode?" % adapter)
180-
return
191+
sys.exit(1)
181192

182193
for key, value in foundMacs.items():
183194
foundMacs[key] = float(sum(value)) / float(len(value))
@@ -254,13 +265,3 @@ def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddre
254265

255266
if __name__ == '__main__':
256267
main()
257-
# oui = {}
258-
# with open('data/oui.txt','r') as f:
259-
# for line in f:
260-
# if '(hex)' in line:
261-
# data = line.split('(hex)')
262-
# key = data[0].replace('-',':').lower().strip()
263-
# company = data[1].strip()
264-
# oui[key] = company
265-
# with open('oui.json','w') as f:
266-
# f.write(json.dumps(oui,indent=2))

0 commit comments

Comments
 (0)