Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell scapy sniff() to stop if no packet is received?

Tags:

python

scapy

How to tell scapy sniff() function to stop if no packet is received ? I'm sending packets with sendp() function Example: when sending DHCP Discover and no response is sent.

like image 402
yoyo Avatar asked Oct 24 '13 14:10

yoyo


People also ask

What is PRN in Scapy sniff?

The prn argument is defined as: prn: function to apply to each packet. If something is returned, it is displayed. For instance you can use prn = lambda x: x.

Which command in Scapy would help you send a packet you just created?

The sr() function is for sending packets and receiving answers. The function returns a couple of packet and answers, and the unanswered packets.

What is TTL in Scapy?

The technique is to send series of packets to the target with Time to Live (TTL) set in such a way that each router on the path will have to notify you of the death of the packet. The traceroute technique is based on the way the IP protocol is designed. TTL value in IP header is seen as hop limit.


1 Answers

The sniff() function in Scapy has a timeout parameter. You can provide a timeout in seconds.

You can find the other options by printing sniff.__doc__.

rypeck@laptop:~$ scapy
>>> print sniff.__doc__
Sniff packets
sniff([count=0,] [prn=None,] [store=1,] [offline=None,] [lfilter=None,] + 
      L2ListenSocket args) -> list of packets

  count: number of packets to capture. 0 means infinity
  store: wether to store sniffed packets or discard them
    prn: function to apply to each packet. If something is returned,
         it is displayed. Ex:
         ex: prn = lambda x: x.summary()
lfilter: python function applied to each packet to determine
         if further action may be done
         ex: lfilter = lambda x: x.haslayer(Padding)
offline: pcap file to read packets from, instead of sniffing them
timeout: stop sniffing after a given time (default: None)
L2socket: use the provided L2socket
opened_socket: provide an object ready to use .recv() on
stop_filter: python function applied to each packet to determine
             if we have to stop the capture after this packet
             ex: stop_filter = lambda x: x.haslayer(TCP)
like image 137
RyPeck Avatar answered Sep 18 '22 15:09

RyPeck