29 lines
811 B
Python
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
|