diff --git a/wifi_monitor.py b/wifi_monitor.py index bed75e6..d4068ae 100755 --- a/wifi_monitor.py +++ b/wifi_monitor.py @@ -665,10 +665,17 @@ class PacketCapture: test_packets = [] try: # Run blocking sniff in executor + # Note: snaplen is not supported for live interface capture in scapy loop = asyncio.get_event_loop() + sniff_kwargs = { + "iface": interface, + "prn": lambda pkt: test_packets.append(pkt), + "timeout": 1, + "store": False + } await loop.run_in_executor( None, - lambda: sniff(iface=interface, prn=lambda pkt: test_packets.append(pkt), timeout=1, store=False, snaplen=self.config.snaplen) + lambda: sniff(**sniff_kwargs) ) except OSError as e: print(f"Error during test capture (system error): {e}") @@ -705,7 +712,7 @@ class PacketCapture: if self.config.full_packet: print("Capturing full packets...") else: - print(f"Capturing packets (snaplen={self.config.snaplen} bytes, header + some payload)...") + print(f"Capturing packets (full packets - snaplen not supported for live capture)...") packets = [] pcap_path = None @@ -719,11 +726,19 @@ class PacketCapture: capture_error = None try: # Run blocking sniff in executor + # Note: snaplen is not supported for live interface capture in scapy + # We capture full packets and can truncate in post-processing if needed loop = asyncio.get_event_loop() + sniff_kwargs = { + "iface": interface, + "prn": lambda pkt: packets.append(pkt), + "timeout": duration, + "store": True + } if self.config.keep_pcap: await loop.run_in_executor( None, - lambda: sniff(iface=interface, prn=lambda pkt: packets.append(pkt), timeout=duration, store=True, snaplen=self.config.snaplen) + lambda: sniff(**sniff_kwargs) ) await loop.run_in_executor(None, lambda: wrpcap(pcap_path, packets)) print(f"Pcap file size: {os.path.getsize(pcap_path)} bytes") @@ -732,7 +747,7 @@ class PacketCapture: else: await loop.run_in_executor( None, - lambda: sniff(iface=interface, prn=lambda pkt: packets.append(pkt), timeout=duration, store=True, snaplen=self.config.snaplen) + lambda: sniff(**sniff_kwargs) ) except KeyboardInterrupt: print("\nCapture interrupted by user")