Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions tests/scripts/dual_tor_sniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
import scapy.all as scapyall


class L2ListenAllSocket(scapyall.conf.L2listen):
"""Read packets at layer2 using Linux PF_PACKET sockets on all ports."""

def __init__(self, *args, **kwargs):
# HACK: Set the socket bind to NOOP, so the packet sockets created
# will not bind to any interface and it will listen on all interfaces
# by default.
socket.bind = lambda _: None
super(L2ListenAllSocket, self).__init__(*args, **kwargs)


class Sniffer(object):
def __init__(self, filter=None, timeout=60):
self.ifaces = [iface for _, iface in socket.if_nameindex() if iface.startswith("eth")]
self.filter = filter
self.timeout = timeout
self.packets = []
Expand All @@ -17,7 +27,7 @@ def sniff(self):
logging.debug("scapy sniffer started: filter={}, timeout={}".format(
self.filter, self.timeout))
scapyall.sniff(
iface=self.ifaces,
L2socket=L2ListenAllSocket,
filter=self.filter,
prn=self.process_pkt,
timeout=self.timeout)
Expand Down
Loading