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

Red text in terminal will be shown when find the target MAC addresses #37

Merged
merged 4 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 27 additions & 4 deletions howmanypeoplearearound/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

from howmanypeoplearearound.oui import oui
from howmanypeoplearearound.analysis import analyze_file

# import colors
from colors import *
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

colors -> howmanypeoplearearound.colors

if os.name != 'nt':
from pick import pick

Expand Down Expand Up @@ -50,6 +53,10 @@ def showTimer(timeleft):
time.sleep(0.1)
print("")

def fileToMacSet(path):
with open(path, 'r') as f:
maclist = f.readlines()
return set([x.strip() for x in maclist])

@click.command()
@click.option('-a', '--adapter', default='', help='adapter to use')
Expand All @@ -65,20 +72,21 @@ def showTimer(timeleft):
@click.option('--loop', help='loop forever', is_flag=True)
@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)
def main(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddresses, nocorrection, loop, analyze, port, sort):
@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):
if analyze != '':
analyze_file(analyze, port)
return
if loop:
while True:
scan(adapter, scantime, verbose, number,
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort)
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs)
else:
scan(adapter, scantime, verbose, number,
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort)
nearby, jsonprint, out, allmacaddresses, nocorrection, loop, sort, targetmacs)


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

# print("OS: " + os.name)
Expand Down Expand Up @@ -143,6 +151,12 @@ def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddre
run_tshark = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output, nothing = run_tshark.communicate()

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

foundMacs = {}
for line in output.decode('utf-8').split('\n'):
if verbose:
Expand Down Expand Up @@ -170,6 +184,15 @@ def scan(adapter, scantime, verbose, number, nearby, jsonprint, out, allmacaddre
for key, value in foundMacs.items():
foundMacs[key] = float(sum(value)) / float(len(value))

# Find target MAC address in foundMacs
if targetmacset:
sys.stdout.write(RED)
for mac in foundMacs:
if mac in targetmacset:
print("Found MAC address: %s" % mac)
print("rssi: %s" % str(foundMacs[mac]))
sys.stdout.write(RESET)

cellphone = [
'Motorola Mobility LLC, a Lenovo Company',
'GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP.,LTD',
Expand Down
9 changes: 9 additions & 0 deletions howmanypeoplearearound/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Output colored text in terminal
# Define colors
RED = "\033[1;31m"
BLUE = "\033[1;34m"
CYAN = "\033[1;36m"
GREEN = "\033[0;32m"
RESET = "\033[0;0m"
BOLD = "\033[;1m"
REVERSE = "\033[;7m"