Enhanced IP resolution with threading support
(self, computers)
| 198 | } |
| 199 | |
| 200 | def resolve_computers_threaded(self, computers): |
| 201 | """Enhanced IP resolution with threading support""" |
| 202 | ip_records = {} |
| 203 | resolution_stats = { |
| 204 | 'total_computers': len(computers), |
| 205 | 'successful_resolutions': 0, |
| 206 | 'total_ips_found': 0, |
| 207 | 'online_computers': 0, |
| 208 | 'methods_used': set() |
| 209 | } |
| 210 | |
| 211 | logger.info(f"🔍 Starting threaded IP resolution for {len(computers)} computers...") |
| 212 | logger.info(f"🌐 DNS Server: {self.dns_server if self.dns_server else 'System default'}") |
| 213 | logger.info(f"🧵 Using {self.max_threads} concurrent threads") |
| 214 | logger.info("=" * 70) |
| 215 | |
| 216 | # Use ThreadPoolExecutor for concurrent DNS resolution |
| 217 | with ThreadPoolExecutor(max_workers=self.max_threads) as executor: |
| 218 | # Submit all DNS resolution tasks |
| 219 | future_to_computer = { |
| 220 | executor.submit(self.resolve_single_computer, computer, False): computer |
| 221 | for computer in computers if computer['computer_name'] |
| 222 | } |
| 223 | |
| 224 | # Collect results as they complete |
| 225 | completed = 0 |
| 226 | for future in as_completed(future_to_computer): |
| 227 | computer = future_to_computer[future] |
| 228 | completed += 1 |
| 229 | |
| 230 | logger.debug(f"[{completed}/{len(future_to_computer)}] Processing: {computer['computer_name']}") |
| 231 | |
| 232 | try: |
| 233 | resolution_result = future.result() |
| 234 | |
| 235 | if resolution_result['ips']: |
| 236 | ip_records[computer['computer_name']] = resolution_result['ips'] |
| 237 | resolution_stats['successful_resolutions'] += 1 |
| 238 | resolution_stats['total_ips_found'] += len(resolution_result['ips']) |
| 239 | resolution_stats['methods_used'].update(resolution_result['methods']) |
| 240 | |
| 241 | if resolution_result['connectivity'] == "Online": |
| 242 | resolution_stats['online_computers'] += 1 |
| 243 | |
| 244 | logger.debug(f"Summary: {len(resolution_result['ips'])} IPs found via {', '.join(resolution_result['methods'])}") |
| 245 | logger.debug(f" IPs: {', '.join(resolution_result['ips'])}") |
| 246 | logger.debug(f" Status: {resolution_result['connectivity']}") |
| 247 | else: |
| 248 | logger.debug(f"No IPs resolved for {computer['computer_name']}") |
| 249 | except Exception as e: |
| 250 | logger.debug(f"Error resolving {computer['computer_name']}: {e}") |
| 251 | |
| 252 | # Print final statistics |
| 253 | logger.info("=" * 70) |
| 254 | logger.info("📊 THREADED RESOLUTION STATISTICS") |
| 255 | logger.info("=" * 70) |
| 256 | logger.info(f"Total computers processed: {resolution_stats['total_computers']}") |
| 257 | logger.info(f"Successful resolutions: {resolution_stats['successful_resolutions']}") |
no outgoing calls
no test coverage detected