简体   繁体   English

为什么 Scapy 中的发件人 IP 地址会增加?

[英]Why does sender IP address increment in Scapy?

I am trying to make a TCP packet that is sent to my other computer 500 times.我正在尝试制作一个 TCP 数据包,该数据包发送到我的另一台计算机 500 次。 I have created this code:我创建了这段代码:

from scapy.all import *
from scapy.utils import rdpcap
#Create your own packets
data = 'This is a test'
myPacket = Ether(src="00:E0:4C:00:02:42",dst="00:E0:4C:01:08:99")/IP(src="169.254.162.71/16",dst="169.254.208.208/16")/TCP()/Raw(load=data)
print(myPacket.show())
for i in range (0,500):
    sendp(myPacket, iface="Ethernet 4")  # sending packet at layer 2

The issue is that when I run this code, the computer receives packets with an incrementing Source IP and the Destination IP is wrong, for some reason:问题是,当我运行此代码时,计算机接收到具有递增源 IP 和目标 IP 的数据包,出于某种原因:

在此处输入图像描述

Any help fixing this would be appreciated.任何解决此问题的帮助将不胜感激。

The /16 in your addresses is called a netmask in CIDR notation.您地址中的/16在 CIDR 表示法中称为网络掩码。 It means that your adresses are subnets that include all possible addresses between 169.254.0.0 and 169.254.255.255 .这意味着您的地址是包含169.254.0.0169.254.255.255之间所有可能地址的子网。 (Same for the source IP) See https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing and https://en.wikipedia.org/wiki/Private_network (源 IP 相同)参见https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routinghttps://en.wikipedia.org/wiki/Private_network

Scapy is going to send 256x256x256x256 (accounting for both sr and dst ) packets with all possible addresses, starting as you saw with the 0.0 ones. Scapy 将发送具有所有可能地址的 256x256x256x256(考虑srdst )数据包,从0.0开始。 You just need to remove the /16 .您只需要删除/16

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM