11import  threading 
22import  sys 
33import  os 
4+ import  os .path 
45import  platform 
56import  subprocess 
67import  json 
910import  netifaces 
1011import  click 
1112
12- from  howmanypeoplearearound .oui  import  oui 
13+ from  howmanypeoplearearound .oui  import  load_dictionary ,  download_oui 
1314from  howmanypeoplearearound .analysis  import  analyze_file 
1415from  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 \t brew install wireshark' )
100111            print (
101112                'you may also need to execute: \n \t brew 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
255266if  __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