6

如果没有收到数据包,如何告诉 scapy sniff() 函数停止?我正在使用 sendp() 函数发送数据包示例:发送 DHCP Discover 时没有发送响应。

4

1 回答 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)
于 2013-10-24T16:26:28.297 回答