scapy,sr1 的问题

Issues with scapy, sr1

我创建了以下代码以便将数据包发送到地址 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

此代码适用于我的机器(即这可能是您的 computer/network 所独有的)。这意味着任何数量的事情之一都可能是错误的:

  • 您在 src 中使用的 IP 地址是错误的(您可以在 linux 上使用 ifconfig 并在 windows 上使用 ipconfig 进行检查) .
  • 超时时间太短(我有时会在 2 秒超时时看到问题并更改为 5 次修复)。如果我将超时设置为 0.001(即 google 不会在 1 毫秒内响应我),我会看到类似于您的输出。
  • 您的防火墙(OS 或路由器)可能会阻止此流量。
  • 一些其他网络问题,例如 DNS 或流量被丢弃。请注意,对于大多数路由器而言,ping 是低优先级流量,因此它们偶尔会丢失,但这并不意味着正常流量会遇到同样的丢失。

这是我更改 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