简体   繁体   中英

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. 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:

在此处输入图像描述

Any help fixing this would be appreciated.

The /16 in your addresses is called a netmask in CIDR notation. It means that your adresses are subnets that include all possible addresses between 169.254.0.0 and 169.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

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. You just need to remove the /16 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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