Python Scapy嗅探过滤器不工作

Python Scapy嗅探过滤器不工作,python,networking,scapy,Python,Networking,Scapy,我在Scapy中对sniff命令应用过滤器时遇到问题。在最简单的情况下,我可以在Scapy cli中嗅探10个数据包,如下所示: Welcome to Scapy (2.3.3) >>> pkts = sniff(count=10) >>> for p in pkts: p.summary() ... 'IP / TCP xx.xx.xx.xx:ssh > xx.xx.xx.xx:53128 PA / Raw' 'IP / TCP xx.xx.xx.x

我在Scapy中对sniff命令应用过滤器时遇到问题。在最简单的情况下,我可以在Scapy cli中嗅探10个数据包,如下所示:

Welcome to Scapy (2.3.3)
>>> pkts = sniff(count=10)
>>> for p in pkts: p.summary()
... 
'IP / TCP xx.xx.xx.xx:ssh > xx.xx.xx.xx:53128 PA / Raw'
'IP / TCP xx.xx.xx.xx:60661 > xx.xx.xx.xx:http_alt PA / Raw'
'IP / TCP xx.xx.xx.xx:http_alt > xx.xx.xx.xx:60661 A'
'IP / TCP xx.xx.xx.xx:32874 > xx.xx.xx.xx:http S'
'IP / TCP xx.xx.xx.xx:https > xx.xx.xx.xx:58026 PA / Raw'
'IP / TCP xx.xx.xx.xx:58026 > xx.xx.xx.xx:https A'
'IP / TCP xx.xx.xx.xx:60804 > xx.xx.xx.xx:http_alt A'
'IP / TCP xx.xx.xx.xx:63244 > xx.xx.xx.xx:http_alt PA / Raw'
'IP / TCP xx.xx.xx.xx:http_alt > xx.xx.xx.xx:63244 A'
'IP / TCP xx.xx.xx.xx:43843 > xx.xx.xx.xx:http_alt A'
但当我尝试时:

pkts = sniff(count=10, filter='tcp')
它永远不会结束,只是等待数据包

我在一个租用的VPS上运行Ubuntu16.04服务器,我知道网络功能有限。例如,我不能使用linux流量控制(tc)

你知道怎么会是这样吗

编辑:
BPF筛选器对于tcpdump确实正常工作。

这可能是因为BPF筛选器没有针对正确的接口进行编译。您应该获得Scapy的当前开发版本(从),并在
sniff()
调用中指定接口:

pkts = sniff(count=10, filter='tcp', iface='eth0')  # replace eth0 with your interface name

谢谢你,皮埃尔。如果我正确地阅读了Github,那么2.3.3是当前版本。但添加iface并不能解决这个问题。我得到了与当前版本相同的behavior2.3.3,但是当前的开发版本包含了许多可能对您有所帮助的修复。这就是为什么我说“你应该得到Scapy的当前开发版本”。你是对的。切换到dev branch修复了各种各样的问题:我的解决方法是使用过滤后的tcpdump创建一个pcap文件,然后将该文件读入python/scapy。也可以嗅探大型pcap文件