我有一些pcap文件,我想按协议(protocol)进行过滤,即如果我想通过HTTP协议(protocol)进行过滤,则除HTTP数据包以外的任何内容都将保留在pcap文件中。
有一个名为openDPI的工具,非常适合我需要的工具,但是没有python语言的包装器。
有谁知道可以执行我需要的任何python模块吗?
谢谢
编辑1:
HTTP过滤只是一个示例,我想过滤很多协议(protocol)。
编辑2:
我尝试了Scapy,但我不知道如何正确过滤。该过滤器仅接受伯克利数据包过滤器表达式,即我无法应用msn或HTTP或其他来自上层的特定过滤器。谁能帮我?

最佳答案

一个使用Scapy的快速示例,因为我刚刚写了一个:

pkts = rdpcap('packets.pcap')
ports = [80, 25]
filtered = (pkt for pkt in pkts if
    TCP in pkt and
    (pkt[TCP].sport in ports or pkt[TCP].dport in ports))
wrpcap('filtered.pcap', filtered)

这将过滤掉既不是HTTP也不是SMTP的数据包。如果要除HTTP和SMTP外的所有数据包,第三行应为:
filtered = (pkt for pkt in pkts if
    not (TCP in pkt and
    (pkt[TCP].sport in ports or pkt[TCP].dport in ports)))
wrpcap('filtered.pcap', filtered)

10-08 18:16