Fallback socket scanning with shorter timeout for when nmap fails
(self, ports_to_scan)
| 1181 | self.logger.debug(f"Full traceback: {traceback.format_exc()}") |
| 1182 | |
| 1183 | def _socket_scan_fallback(self, ports_to_scan): |
| 1184 | """Fallback socket scanning with shorter timeout for when nmap fails""" |
| 1185 | fallback_start_time = time.time() |
| 1186 | self.logger.info(f"🔌 SOCKET FALLBACK: Scanning {self.target} with {len(ports_to_scan)} ports") |
| 1187 | |
| 1188 | initial_open_count = len(self.open_ports[self.target]) |
| 1189 | |
| 1190 | with ThreadPoolExecutor(max_workers=min(4, self.outer_instance.port_scan_workers)) as executor: |
| 1191 | futures = [executor.submit(self._scan_port_socket, port) for port in ports_to_scan] |
| 1192 | completed_scans = 0 |
| 1193 | failed_scans = 0 |
| 1194 | |
| 1195 | for future in futures: |
| 1196 | try: |
| 1197 | future.result(timeout=5) # 5 second timeout per port |
| 1198 | completed_scans += 1 |
| 1199 | except Exception as e: |
| 1200 | failed_scans += 1 |
| 1201 | self.logger.debug(f"Socket scan future failed: {e}") |
| 1202 | |
| 1203 | fallback_duration = time.time() - fallback_start_time |
| 1204 | final_open_count = len(self.open_ports[self.target]) |
| 1205 | new_ports_found = final_open_count - initial_open_count |
| 1206 | |
| 1207 | if new_ports_found > 0: |
| 1208 | self.logger.info(f"🎉 SOCKET FALLBACK SUCCESS: Found {new_ports_found} additional open ports on {self.target} in {fallback_duration:.2f}s") |
| 1209 | else: |
| 1210 | self.logger.warning(f"❌ SOCKET FALLBACK COMPLETE: No additional ports found on {self.target} in {fallback_duration:.2f}s (completed: {completed_scans}, failed: {failed_scans})") |
| 1211 | |
| 1212 | def _scan_port_socket(self, port): |
| 1213 | """Fallback socket scanning method with aggressive timeout""" |