Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 scapy 中创建了一个嗅探器,我希望将 scapy 捕获的数据包写入文件以进行进一步分析?
def sniffer(ip): filter_str = "icmp and host " + ip packets=sniff(filter=filter_str,count=20) f = open('log.txt',"a") #f.write(packets)
最后一行代码不起作用。有什么办法可以做到这一点吗?
f.write需要一个字符缓冲区,但您为它提供一个Sniffed对象,该对象是调用sniff. 您可以非常简单地执行以下操作:
f.write
Sniffed
sniff
f.write(str(packets))
这应该有效。但它可能不会完全按照您的意愿显示信息。在packets写入f.
packets
f