Scapy BPF filter not working

瘦欲@ 提交于 2019-12-21 09:10:11

问题


I am using Scapy and would like to filter based on the destination mac address.

However, I am getting packets displayed where the destination MAC address is not the address specified in the filter.

Here is a code snippit:

from scapy.all import *

sniff(iface="eth1", filter="ether dst host 91:e0:f0:01:00:00", 
      count=3, prn=lambda x: x.show())

I am running Scapy 2.2.0

Any ideas on the issue here?


回答1:


Scapy requires numerous dependencies for many different systems. It is quiet possible that you don't have the required dependency for BPF filters to work.

http://www.secdev.org/projects/scapy/portability.html




回答2:


It's scapy fault!!! It seems that scapy starts receiving packets before applying the BPF filter (filter argument of sniff function). It takes a while to get work properly! Two methods to get rid of this:

  1. Use lfilter to define your filtering function inside the script. It's not efficient on busy link because filter is applied in your script, instead of kernel. Consider using pypy to speed it up.
  2. For some first packets check destination MAC address inside your script and then don't check it anymore; i.e check correctness of the packet in the beginning time of sniffing to pass unstable phase of scapy and then rely on scapy to filter the unwanted packets.



回答3:


Installing tcpdump solved the problem for me - now the filter on sniff works




回答4:


In my case, upgrading to 2.3.3dev (github version), fixed it



来源:https://stackoverflow.com/questions/12011089/scapy-bpf-filter-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!