以阻塞方式,我可以这样做:
from scapy.all import *
sniff(filter"tcp and port 80", count=10, prn = labmda x:x.summary())
# Below code will be executed only after 10 packets have been received
do_stuff()
do_stuff2()
do_stuff3()
我希望能够以非阻塞方式嗅探带有 scapy 的数据包,如下所示:
def packet_recevied_event(p):
print "Packet received event!"
print p.summary()
# The "event_handler" parameter is my wishful thinking
sniff(filter"tcp and port 80", count=10, prn=labmda x:x.summary(),
event_handler=packet_received_event)
#I want this to be executed immediately
do_stuff()
do_stuff2()
do_stuff3()
总结一下:我的问题很清楚,我希望能够继续执行代码而不会被嗅探功能阻塞。一种选择是为此打开一个单独的线程,但我想避免它并尽可能使用 scapy 本机工具。
环境细节:
蟒蛇:2.7
斯皮比:2.1.0
操作系统:ubuntu 12.04 64bit