Start traffic capture and analysis
(self)
| 512 | logger.debug(f"Socket IP detection error: {e}") |
| 513 | |
| 514 | # Method 3: Try to get IPs from shared_data if available (Flask config) |
| 515 | if self.shared_data: |
| 516 | try: |
| 517 | # Check if there's a configured host IP |
| 518 | host = self.shared_data.get('host', '') |
| 519 | if host and host not in ['0.0.0.0', '']: |
| 520 | local_ips.add(host) |
| 521 | logger.debug(f"Detected local IP (config): {host}") |
| 522 | except Exception: |
| 523 | pass |
| 524 | |
| 525 | # Add common local network ranges that might be Ragnar |
| 526 | # These are private IP patterns that are likely to be the host |
| 527 | try: |
| 528 | for ip in list(local_ips): |
| 529 | if ip.startswith('192.168.') or ip.startswith('10.') or ip.startswith('172.'): |
| 530 | # This is a private IP, likely the actual machine IP |
| 531 | logger.info(f"Ragnar local IP detected: {ip}") |
| 532 | except Exception: |
| 533 | pass |
| 534 | |
| 535 | logger.info(f"Local IPs (excluded from alerts): {local_ips}") |
| 536 | return local_ips |
| 537 | |
| 538 | def _detect_gateway_ips(self) -> set: |
| 539 | gateways: set = set() |
| 540 | try: |
| 541 | result = subprocess.run( |
| 542 | ['ip', 'route', 'show', 'default'], |
| 543 | capture_output=True, text=True, timeout=5 |
| 544 | ) |
| 545 | if result.returncode == 0: |
| 546 | for match in re.finditer( |
| 547 | r'default\s+via\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', |
| 548 | result.stdout |
| 549 | ): |
| 550 | gateways.add(match.group(1)) |
| 551 | except Exception as e: |
| 552 | logger.debug(f"Gateway detection error: {e}") |
| 553 | if gateways: |
no test coverage detected