同时发送几个数据包并得到答案

时间:2017-08-22 16:13:07

标签: scapy

我试图发送4个数据包并为每个人获得一个答案(例如" ping" CMD上的工具),我该怎么做? 包:

packet = IP(dst = "www.google.com")/ICMP()/"hi"

我知道我可以这样发送:send(packet, count=4)但我需要所有人的回答。 sr1(packet)只发送了一次sr()我没有意识到如何使用它发送4个数据包并得到答案...

我试着在第35页看http://www.secdev.org/projects/scapy/files/scapydoc.pdf

非常感谢!!!

1 个答案:

答案 0 :(得分:0)

首先sr()用于发送数据包和接收答案,而sr1()是仅返回发送数据包的第一个答案的变体。您可以通过键入help(sr1)(或任何其他功能)从python或scapy的交互式控制台中找到更多信息here,您可以查看有关该功能的详细信息:

sr1(x, filter=None, iface=None, nofilter=0, *args, **kargs)
    Send packets at layer 3 and return only the first answer
    nofilter: put 1 to avoid use of bpf filters
    retry:    if positive, how many times to resend unanswered packets
              if negative, how many times to retry when no more packets are answered
    timeout:  how much time to wait after the last packet has been sent
    verbose:  set verbosity level
    multi:    whether to accept multiple answers for the same stimulus
    filter:   provide a BPF filter
    iface:    listen answers only on the given interface

现在连续4次发送这些数据包,并为每个数据包得到答案,你可以试试:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from scapy.all import *

packet = IP(dst = "www.google.com")/ICMP()/"hi"
for _ in range(4):
    answer = sr1(packet)
    answer.show()