有没有人能帮我把嗅探到的包保存到一个文件中?我需要使用keyboardInterrupt来嗅探,并将嗅探到的数据包保存到pcap文件中,问题是keyboardInterrupt会使嗅探到的数据包消失,那么有没有办法在嗅探的同时保存数据包呢?或者即使有异常也要将它们保存到变量中?
这就是我到目前为止所尝试的,但是exeption阻止了它被保存:
from scapy.all import *
try:
packets = sniff()
except KeyboardInterrupt as ki:
pass发布于 2017-07-09 22:52:15
也许你可以使用一个函数来存储它们
from scapy.all import *
packet_list = []
def storepkt(pkt):
packet_list.append(pkt)
try:
sniff(ptr=storepkt)
except KeyboardInterrupt as ki:
#Here you should have access to the packet_list list and do whatever you need with them, i.e.:
for pkt in packet_list:
pkt.show()注意,这段代码是针对Python2.7的。
https://stackoverflow.com/questions/44805845
复制相似问题