同时发送几个数据包并得到答复
sending few packet at the same time and get answer
我正在尝试发送 4 个数据包并为每个数据包获取一个答案(就像 CMD 上的 "ping" 工具),我该怎么做?
数据包:
packet = IP(dst = "www.google.com")/ICMP()/"hi"
我知道我可以这样发送:send(packet, count=4)
但是我需要所有的答案。
sr1(packet)
只发送了一次 sr()
我不知道如何使用它发送 4 个数据包并得到答复...
我试着看这里 http://www.secdev.org/projects/scapy/files/scapydoc.pdf 第 35 页
非常感谢!!!
首先,sr()
用于发送数据包和接收应答,而 sr1()
是一种变体,仅 returns 发送数据包的第一个应答。您可以找到更多信息 here,当然也可以从 python 或 scapy 的交互式控制台键入 help(sr1)
(或任何其他函数),您可以查看有关该函数的详细信息:
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()
我正在尝试发送 4 个数据包并为每个数据包获取一个答案(就像 CMD 上的 "ping" 工具),我该怎么做? 数据包:
packet = IP(dst = "www.google.com")/ICMP()/"hi"
我知道我可以这样发送:send(packet, count=4)
但是我需要所有的答案。
sr1(packet)
只发送了一次 sr()
我不知道如何使用它发送 4 个数据包并得到答复...
我试着看这里 http://www.secdev.org/projects/scapy/files/scapydoc.pdf 第 35 页
非常感谢!!!
首先,sr()
用于发送数据包和接收应答,而 sr1()
是一种变体,仅 returns 发送数据包的第一个应答。您可以找到更多信息 here,当然也可以从 python 或 scapy 的交互式控制台键入 help(sr1)
(或任何其他函数),您可以查看有关该函数的详细信息:
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()