Test connectivity to multiple hosts using threading
(self, hostnames)
| 265 | return ip_records |
| 266 | |
| 267 | def test_connectivity_threaded(self, hostnames): |
| 268 | """Test connectivity to multiple hosts using threading""" |
| 269 | if not hostnames: |
| 270 | return {} |
| 271 | |
| 272 | logger.info(f"🏓 Starting threaded ping test for {len(hostnames)} hosts...") |
| 273 | logger.info(f"🧵 Using {self.max_threads} concurrent threads") |
| 274 | |
| 275 | connectivity_results = {} |
| 276 | |
| 277 | # Use ThreadPoolExecutor for concurrent ping tests |
| 278 | with ThreadPoolExecutor(max_workers=self.max_threads) as executor: |
| 279 | # Submit all ping tasks |
| 280 | future_to_hostname = { |
| 281 | executor.submit(self.test_connectivity, hostname): hostname |
| 282 | for hostname in hostnames |
| 283 | } |
| 284 | |
| 285 | # Collect results as they complete |
| 286 | completed = 0 |
| 287 | for future in as_completed(future_to_hostname): |
| 288 | hostname = future_to_hostname[future] |
| 289 | completed += 1 |
| 290 | |
| 291 | try: |
| 292 | is_online = future.result() |
| 293 | connectivity_results[hostname] = is_online |
| 294 | status = "Online" if is_online else "Offline" |
| 295 | logger.debug(f"[{completed}/{len(hostnames)}] {hostname}: {status}") |
| 296 | except Exception as e: |
| 297 | connectivity_results[hostname] = False |
| 298 | logger.debug(f"[{completed}/{len(hostnames)}] {hostname}: Error - {e}") |
| 299 | |
| 300 | online_count = sum(1 for online in connectivity_results.values() if online) |
| 301 | logger.info(f"📊 Ping test complete: {online_count}/{len(hostnames)} hosts online") |
| 302 | |
| 303 | return connectivity_results |
| 304 | |
| 305 | |
| 306 | def match_ips_to_subnets(ad_subnets, ip_records): |
no outgoing calls
no test coverage detected