freebsd-dev/tests/sys/netpfil/pf/sniffer.py
Kristof Provost d1805f60af pf tests: Move Sniffer to its own file
Make it easier to re-use the sniffer class in other test support
scripts.
2019-03-21 08:15:46 +00:00

26 lines
556 B
Python

# $FreeBSD$
import threading
import scapy.all as sp
class Sniffer(threading.Thread):
def __init__(self, args, check_function):
threading.Thread.__init__(self)
self._args = args
self._recvif = args.recvif[0]
self._check_function = check_function
self.foundCorrectPacket = False
self.start()
def _checkPacket(self, packet):
ret = self._check_function(self._args, packet)
if ret:
self.foundCorrectPacket = True
return ret
def run(self):
self.packets = sp.sniff(iface=self._recvif,
stop_filter=self._checkPacket, timeout=3)