I'm writing a program that needs to re-filter the packets captured by sniff().I want to apply BPF filer to each packet and if it matches, return true, else return false.
Could any one give me some hints?Thanks!
I'm writing a program that needs to re-filter the packets captured by sniff().I want to apply BPF filer to each packet and if it matches, return true, else return false.
Could any one give me some hints?Thanks!
Copyright © 2021 Jogjafile Inc.
For the record, this is my answer on the issue you have opened:
You don't need a
BytesIOobject, since theofflineparameter ofsniff()can accept aPacketListor a singlePacket.You can do:
The data is passed to a
tcpdumpprocess through its standard input, so it won't touch your hard drive, unless you're using MacOS X (but that's a tcpdump / MacOS X limitation, Scapy cannot do better here).If you want a per packet test, you can do:
Please not that this will fork a
tcpdumpprocess for each packet, which is probably not ideal.As a side note, if your test is that simple, you can also use a Scapy test instead (it's not strictly equivalent though, but can be helpful in some situations and will not fork a process for each processed packet):