Sebastian Lenzlinger a78222a0e6 Devel
2024-05-02 02:08:09 +00:00

29 lines
811 B
Python

import shutil
import subprocess
def check_installed() -> bool:
"""Check if tcpdump is installed and available on the system path."""
return shutil.which('tcpdump') is not None
def ensure_installed():
"""Ensure that tcpdump is installed, raise an error if not."""
if not check_installed():
raise RuntimeError("tcpdump is not installed. Please install it to continue.")
def list_interfaces() -> str:
"""List available network interfaces using tcpdump."""
ensure_installed()
try:
result = subprocess.run(['tcpdump', '--list-interfaces'], capture_output=True, text=True, check=True)
return result.stdout
except subprocess.CalledProcessError as e:
print(f"Failed to list interfaces: {e}")
return ""
def start_tcpdump():
return None