4

I am having an issue with scapy's timeout option when sniffing packets. From what I understand, if you use something like this :

test = sniff(filter="ip and icmp ", timeout = 2)
print(test)

your sniffing should time out after 2 seconds. However, this is 100% not working. From what I have gathered, one of the biggest problems as well, is if you set timeout = 5 and run the sniffer, then run a ping google.com in a parallel command prompt, it will capture the 4 packets not displayed until sniff is done then sit there indefinitely, until you send or receive 1 more icmp packet, just one, then it'll kill the sniff and print(test) with 5 total icmp 4 from first ping set, 1 from second ping.

I am using windows, which might be the issue I don't know. I have python 2.7. my entire script, for testing this 1 thing had to isolate it from a much bigger script is as such:

from scapy.all import *



test = sniff(filter="ip and icmp ", timeout = 5)
print(test)

that's it - if timeout = 1, it will not stop until a packet is received as well.

This is the code from scapy's sendrecv.py for sniff timeout

if timeout is not None:
    stoptime = time.time()+timeout
remain = None
while 1:
    try:
        if timeout is not None:
            remain = stoptime-time.time()
            if remain <= 0:
                break

After ripping the function out of scapy sendrecv.py and realizing the function has the same problem, I have narrowed the problem down. It appears when you pass a filter into the sniff function it alters the way timeout works. If you run :

from scapy.all import *

test = sniff(timeout = 5)
print(test)

you will be fine, it'll auto timeout at 5 seconds, otherwise it hangs and doesn't complete the timeout loop properly.

In the stars
  • 253
  • 4
  • 17
  • This sounds more like a bug than a question. I recommend you submitting it to scapy issue list. I just verified it on scapy3k (http://github.com/phaethon/scapy), and I cannot repeat the problem. Also, it is significant that you name your platform as sendrcv code in scapy is different for different platforms. – Eriks Dobelis Nov 25 '15 at 08:33
  • when you say name your platform, do you mean something like this? "I am using windows, which might be the issue I don't know. I have python 2.7." That was included already, if not I don't know what else you would be referring to. – In the stars Nov 25 '15 at 10:10
  • Sorry, did not notice mention of Windows earlier. – Eriks Dobelis Nov 25 '15 at 10:14
  • I know windows isn't exactly the most "supported" platform, but doing class project and instructor isn't going to be using linux. Need to make sure it works here. – In the stars Nov 25 '15 at 10:29
  • 1
    As I said - it works for me on Windows. Just using scapy3k. May be your instructor will accept python3. – Eriks Dobelis Nov 25 '15 at 10:39

1 Answers1

0

I have tried the exact same code, and it works for me perfectly. Try reinstalling scapy, or revert to older versions. I found that for me 2.2.0dev is one of the more stable builds.