From 847ed8328879527b806688f9b123c8a8a3408c91 Mon Sep 17 00:00:00 2001 From: Phil <phil@secdev.org> Date: Thu, 5 Nov 2009 13:44:37 +0100 Subject: [PATCH] Added opened_socked parameter to sniff() --- scapy/sendrecv.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/scapy/sendrecv.py b/scapy/sendrecv.py index 321922ce..75e84a5c 100644 --- a/scapy/sendrecv.py +++ b/scapy/sendrecv.py @@ -522,7 +522,7 @@ iface: listen answers only on the given interface""" @conf.commands.register -def sniff(count=0, store=1, offline=None, prn = None, lfilter=None, L2socket=None, timeout=None, *arg, **karg): +def sniff(count=0, store=1, offline=None, prn = None, lfilter=None, L2socket=None, timeout=None, opened_socket=None, *arg, **karg): """Sniff packets sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + L2ListenSocket args) -> list of packets @@ -537,15 +537,19 @@ lfilter: python function applied to each packet to determine offline: pcap file to read packets from, instead of sniffing them timeout: stop sniffing after a given time (default: None) L2socket: use the provided L2socket +opened_socket: provide an object ready to use .recv() on """ c = 0 - - if offline is None: - if L2socket is None: - L2socket = conf.L2listen - s = L2socket(type=ETH_P_ALL, *arg, **karg) + + if opened_socket is not None: + s = opened_socket else: - s = PcapReader(offline) + if offline is None: + if L2socket is None: + L2socket = conf.L2listen + s = L2socket(type=ETH_P_ALL, *arg, **karg) + else: + s = PcapReader(offline) lst = [] if timeout is not None: @@ -575,7 +579,8 @@ L2socket: use the provided L2socket break except KeyboardInterrupt: break - s.close() + if opened_socket is None: + s.close() return plist.PacketList(lst,"Sniffed") @conf.commands.register -- GitLab