0

Using the sendpfast function, how can I send UDP Packets from a randomized source? I need to do this for network simulation experimentation purposes.

I have a code like this where I set source IP and port:

IP1 = Ether() / IP(src=self.IPsrc,dst=self.IPdst)
UDP1 = UDP(sport=self.IPsrcport, dport=self.IPdstport);
pkt = IP1 / UDP1
sendpfast(pkt/"Hello World", mbps=5, loop=1000)

I would like to randomize it for every packet.

user963241
  • 6,758
  • 19
  • 65
  • 93

1 Answers1

1

Use the RandIP function for ip:

from scapy.all import RandIP
IP1 = Ether() / IP(src=RandIP(), dst=self.IPdst)

and for the port create your own:

import random
sport = random.randint(1024,65535)
UDP1 = UDP(sport=sport, dport=self.IPdstport);

Luc
  • 156
  • 3