MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / _analysis_loop

Method _analysis_loop

traffic_analyzer.py:650–688  ·  view source on GitHub ↗

Process captured packets and generate statistics

(self)

Source from the content-addressed store, hash-verified

648
649 try:
650 self._stop_sidecars()
651 except Exception as exc:
652 logger.debug(f"Sidecar shutdown failed: {exc}")
653
654 if self._capture_process:
655 try:
656 self._capture_process.terminate()
657 self._capture_process.wait(timeout=5)
658 except Exception as e:
659 logger.error(f"Error stopping capture: {e}")
660 try:
661 self._capture_process.kill()
662 except Exception:
663 pass
664
665 logger.info("Traffic analyzer stopped")
666
667 def _capture_loop(self):
668 """Main capture loop using tcpdump"""
669 try:
670 # Build tcpdump command
671 # -l: line-buffered, -n: no DNS resolution, -q: quiet (brief output)
672 # -tttt: timestamp format
673 cmd = [
674 'sudo', 'tcpdump',
675 '-i', self.interface,
676 '-l', '-n', '-q',
677 '-tttt',
678 'not port 22 and not port 8000' # Exclude SSH and web UI traffic
679 ]
680
681 logger.info(f"Starting tcpdump: {' '.join(cmd)}")
682
683 self._capture_process = subprocess.Popen(
684 cmd,
685 stdout=subprocess.PIPE,
686 stderr=subprocess.PIPE,
687 text=True,
688 bufsize=1
689 )
690
691 # Start stderr reader thread to capture errors

Callers

nothing calls this directly

Calls 8

_process_packet_batchMethod · 0.95
_update_metricsMethod · 0.95
_sweep_beaconsMethod · 0.95
_passive_sync_to_dbMethod · 0.95
appendMethod · 0.80
debugMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected