我创建了伪造的代码,以便将数据包发送到www.google.com,但没有得到任何答复。
CODE
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
此代码可在我的计算机上使用(即,这可能是您的计算机/网络所独有的)。这意味着许多事情之一可能是错误的:
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'
None