我创建了灵活的代码,以便向address www.google.com发送一个数据包,但我没有得到任何答复。
代码
from scapy.all import IP, ICMP, sr1
ip_layer = IP(src='192.168.224.131', dst='www.google.com')
#rint(ip_layer.show())
icmp_req = ICMP()
#print(icmp_req.show())
packet = ip_layer / icmp_req
#print(packet.show())
received_packet = sr1(packet, timeout=2)
if received_packet:
print(received_packet.show()) 输出
Begin emission:
.Finished sending 1 packets.
Received 1 packets, got 0 answers, remaining 1 packets发布于 2020-05-26 02:51:00
此代码在我的计算机上工作(也就是说,这可能是您的计算机/网络所特有的)。这意味着任何一件事都可能是错误的:
src中使用的IP地址是错误的(您可以在linux上用ifconfig检查这个地址,在windows上用ipconfig检查这个地址)。这是更改src IP地址后得到的响应:
bash-5.0$ python temp.py
Begin emission:
....Finished sending 1 packets.
.*
Received 6 packets, got 1 answers, remaining 0 packets
###[ IP ]###
version = 4
ihl = 5
tos = 0x0
len = 28
id = 0
flags =
frag = 0
ttl = 50
proto = icmp
chksum = 0xfe6
src = 172.217.9.132
dst = 192.168.1.246
\options \
###[ ICMP ]###
type = echo-reply
code = 0
chksum = 0x0
id = 0x0
seq = 0x0
###[ Padding ]###
load = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Nonehttps://stackoverflow.com/questions/62009681
复制相似问题