Validate multiple IP:port combinations using threading/multiprocessing Args: ip_port_list: List of (ip, port) tuples **kwargs: Additional protocol-specific parameters Returns: dict: Results keyed by "ip:port" strings
(self, ip_port_list, **kwargs)
| 55 | pass |
| 56 | |
| 57 | def validate_targets_threaded(self, ip_port_list, **kwargs): |
| 58 | """ |
| 59 | Validate multiple IP:port combinations using threading/multiprocessing |
| 60 | |
| 61 | Args: |
| 62 | ip_port_list: List of (ip, port) tuples |
| 63 | **kwargs: Additional protocol-specific parameters |
| 64 | |
| 65 | Returns: |
| 66 | dict: Results keyed by "ip:port" strings |
| 67 | """ |
| 68 | if not ip_port_list: |
| 69 | return {} |
| 70 | |
| 71 | # Filter only relevant ports if the validator defines specific ports |
| 72 | relevant_ports = self.get_default_ports() |
| 73 | if relevant_ports: |
| 74 | ip_port_list = [(ip, port) for ip, port in ip_port_list if port in relevant_ports] |
| 75 | |
| 76 | if not ip_port_list: |
| 77 | logger.info(f"No {self.protocol_name} ports found for validation") |
| 78 | return {} |
| 79 | |
| 80 | logger.info(f"Starting {self.protocol_name} validation for {len(ip_port_list)} targets...") |
| 81 | logger.info(f"Threads: {self.max_threads}, Timeout: {self.timeout}s") |
| 82 | |
| 83 | results = {} |
| 84 | |
| 85 | # Always use threading (multiprocessing disabled for stability) |
| 86 | with ThreadPoolExecutor(max_workers=self.max_threads) as executor: |
| 87 | # Submit all validation tasks |
| 88 | future_to_target = { |
| 89 | executor.submit(self.validate_single_target, ip, port, **kwargs): f"{ip}:{port}" |
| 90 | for ip, port in ip_port_list |
| 91 | } |
| 92 | |
| 93 | # Collect results as they complete |
| 94 | completed = 0 |
| 95 | for future in as_completed(future_to_target): |
| 96 | target = future_to_target[future] |
| 97 | completed += 1 |
| 98 | |
| 99 | try: |
| 100 | result = future.result() |
| 101 | results[target] = result |
| 102 | self._log_result(target, result, completed, len(ip_port_list)) |
| 103 | except Exception as e: |
| 104 | results[target] = self._create_error_result(str(e)) |
| 105 | logger.debug(f"[{completed}/{len(ip_port_list)}] {target}: Validation error - {e}") |
| 106 | |
| 107 | # Summary |
| 108 | successful = sum(1 for r in results.values() |
| 109 | if r.get(self.protocol_name.lower(), {}).get('status', False)) |
| 110 | logger.info(f"{self.protocol_name} validation results: {successful}/{len(ip_port_list)} successful") |
| 111 | |
| 112 | return results |
| 113 | |
| 114 | def _worker_process(self, args): |
no test coverage detected