Skip to content

Commit

Permalink
Red text in terminal will be shown when find the target MAC addresses (
Browse files Browse the repository at this point in the history
…#37)

Red text in terminal will be shown when find the target MAC addresses
  • Loading branch information
Yuchen Sun authored and schollz committed Oct 6, 2017
1 parent 728a6d4 commit 0d0e4a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
31 changes: 26 additions & 5 deletions howmanypeoplearearound/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

from howmanypeoplearearound.oui import oui
from howmanypeoplearearound.analysis import analyze_file
from howmanypeoplearearound.colors import *

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


def which(program):
"""Determines whether program exists
"""
Expand Down Expand Up @@ -50,6 +51,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 +70,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:
adapter = 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 +149,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 +182,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"

0 comments on commit 0d0e4a7

Please sign in to comment.