File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55import scapy .all as scapyall
66
77
8+ class L2ListenAllSocket (scapyall .conf .L2listen ):
9+ """Read packets at layer2 using Linux PF_PACKET sockets on all ports."""
10+
11+ def __init__ (self , * args , ** kwargs ):
12+ # HACK: Set the socket bind to NOOP, so the packet sockets created
13+ # will not bind to any interface and it will listen on all interfaces
14+ # by default.
15+ socket .bind = lambda _ : None
16+ super (L2ListenAllSocket , self ).__init__ (* args , ** kwargs )
17+
18+
819class Sniffer (object ):
920 def __init__ (self , filter = None , timeout = 60 ):
10- self .ifaces = [iface for _ , iface in socket .if_nameindex () if iface .startswith ("eth" )]
1121 self .filter = filter
1222 self .timeout = timeout
1323 self .packets = []
@@ -17,7 +27,7 @@ def sniff(self):
1727 logging .debug ("scapy sniffer started: filter={}, timeout={}" .format (
1828 self .filter , self .timeout ))
1929 scapyall .sniff (
20- iface = self . ifaces ,
30+ L2socket = L2ListenAllSocket ,
2131 filter = self .filter ,
2232 prn = self .process_pkt ,
2333 timeout = self .timeout )
You can’t perform that action at this time.
0 commit comments