()
| 89 | |
| 90 | |
| 91 | def dumpcap_usable(): |
| 92 | def have_binary(name): |
| 93 | return shutil.which(name) is not None |
| 94 | |
| 95 | if not have_binary("dumpcap") or not have_binary("tshark"): |
| 96 | return False |
| 97 | |
| 98 | try: |
| 99 | with tempfile.TemporaryDirectory() as td: |
| 100 | pcap = Path(td) / "probe.pcap" |
| 101 | |
| 102 | proc = subprocess.Popen( |
| 103 | [ |
| 104 | "dumpcap", |
| 105 | "-i", "lo", |
| 106 | "-w", str(pcap), |
| 107 | "-f", "tcp", |
| 108 | ], |
| 109 | stdout=subprocess.DEVNULL, |
| 110 | stderr=subprocess.DEVNULL, |
| 111 | ) |
| 112 | |
| 113 | time.sleep(0.2) |
| 114 | proc.terminate() |
| 115 | proc.wait(timeout=1) |
| 116 | |
| 117 | return pcap.exists() and pcap.stat().st_size > 0 |
| 118 | except (PermissionError, subprocess.SubprocessError, OSError): |
| 119 | return False |
| 120 | |
| 121 | |
| 122 | class TcpCapture: |
no test coverage detected