python - 如果没有收到数据包,如何告诉 scapy sniff() 停止?

标签 python scapy

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

最佳答案

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)

关于python - 如果没有收到数据包,如何告诉 scapy sniff() 停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19568645/

相关文章:

c# - Python 中使用十六进制进行位移位

python - 实时面部识别:PermissionError:[Errno 13]权限被拒绝:

tcp - Scapy 设置 tcp 流窗口大于 65535

python - 如何将 pcap 文件中的 Raw 部分转换为正常格式?

python - Scapy 将 proto 作为 ipv4 数据包的 ipv6 发送

python - ndb 中的多对多关系

python - 如何正确地将 Python 脚本输出重定向到文件?

python - Pandas :根据条件按行替换值

python - 使用 sniff() 函数的 Scapy 过滤

Python 在使用 Scapy 创建空 pcap 文件时抑制警告