如何告诉scapy的sniff()函数如果没有收到数据包就停止?

6
如何告诉Scapy的sniff()函数在没有收到数据包时停止? 我使用sendp()函数发送数据包。 例如:发送DHCP Discover,但未收到响应。
1个回答

6

Scapy中的sniff()函数有一个超时参数。您可以提供以秒为单位的超时时间。

您可以通过打印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)

是的,我知道超时的问题,但我在想是否有一种方法可以在自己编程的时间之后没有任何输入时阻止它。 - yoyo
据我所知,超时是您唯一的选择。其他所有操作都需要接收数据包。 - RyPeck

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接