@@ -184,23 +184,17 @@ def get_targets(self, old_targets=None, apply_filter=True, target_archives=None)
184184 new_targets = Airodump .get_targets_from_csv (csv_filename )
185185
186186 # Check if one of the targets is also contained in the old_targets
187+ # Use dict lookup (O(1)) instead of nested loop (O(n*m))
188+ old_by_bssid = {t .bssid : t for t in old_targets }
187189 for new_target in new_targets :
188- just_found = True
189- for old_target in old_targets :
190- # If the new_target is found in old_target copy attributes from old target
191- if old_target == new_target :
192- # Identify decloaked targets
193- if new_target .essid_known and not old_target .essid_known :
194- # We decloaked a target!
195- new_target .decloaked = True
196-
197- old_target .transfer_info (new_target )
198- just_found = False
199- break
200-
201- # If the new_target is not in old_targets, check target_archives
202- # and copy attributes from there
203- if just_found and new_target .bssid in target_archives :
190+ old_target = old_by_bssid .get (new_target .bssid )
191+ if old_target is not None :
192+ # Identify decloaked targets
193+ if new_target .essid_known and not old_target .essid_known :
194+ new_target .decloaked = True
195+ old_target .transfer_info (new_target )
196+ elif new_target .bssid in target_archives :
197+ # If the new_target is not in old_targets, check target_archives
204198 target_archives [new_target .bssid ].transfer_info (new_target )
205199
206200 # Check targets for WPS
@@ -237,18 +231,22 @@ def get_targets_from_csv(csv_filename):
237231 targets2 = []
238232 import csv
239233
234+ # Detect encoding from first 4KB sample to avoid reading entire file twice
240235 try :
241236 import chardet
242- with open (csv_filename , "rb" ) as rawdata :
243- encoding = chardet .detect (rawdata .read ())['encoding' ] or 'utf-8'
237+ with open (csv_filename , 'rb' ) as rawdata :
238+ encoding = chardet .detect (rawdata .read (4096 ))['encoding' ] or 'utf-8'
244239 except ImportError :
245240 encoding = 'utf-8'
246241
247242 with open (csv_filename , 'r' , encoding = encoding , errors = 'ignore' ) as csvopen :
248243 lines = []
244+ has_null = False
249245 for line in csvopen :
250246 if '\0 ' in line :
251- log_warning ('Airodump' , 'Null bytes found in CSV data, stripping them' )
247+ if not has_null :
248+ log_warning ('Airodump' , 'Null bytes found in CSV data, stripping them' )
249+ has_null = True
252250 line = line .replace ('\0 ' , '' )
253251 lines .append (line )
254252
@@ -272,6 +270,12 @@ def get_targets_from_csv(csv_filename):
272270 elif row [0 ].strip () == 'Station MAC' :
273271 # This is the 'header' for the list of Clients
274272 hit_clients = True
273+ # Build BSSID lookup dict for O(1) client-to-target matching
274+ # Use first occurrence per BSSID to match original behavior
275+ targets_by_bssid = {}
276+ for t in targets2 :
277+ if t .bssid not in targets_by_bssid :
278+ targets_by_bssid [t .bssid ] = t
275279 continue
276280
277281 if hit_clients :
@@ -286,11 +290,10 @@ def get_targets_from_csv(csv_filename):
286290 # Ignore unassociated clients
287291 continue
288292
289- # Add this client to the appropriate Target
290- for t in targets2 :
291- if t .bssid == client .bssid :
292- t .clients .append (client )
293- break
293+ # Add this client to the appropriate Target (O(1) dict lookup)
294+ target = targets_by_bssid .get (client .bssid )
295+ if target :
296+ target .clients .append (client )
294297
295298 else :
296299 # The current row corresponds to a 'Target' (router)
0 commit comments