Python sendpfast scapy发送伪造的udp

Python sendpfast scapy发送伪造的udp,python,python-3.x,scapy,Python,Python 3.x,Scapy,使用sendpfast函数,如何从随机源发送UDP数据包?我需要这样做的目的是网络模拟实验 我有一个这样的代码,其中我设置了源IP和端口: 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) 我想对每个数据包

使用sendpfast函数,如何从随机源发送UDP数据包?我需要这样做的目的是网络模拟实验

我有一个这样的代码,其中我设置了源IP和端口:

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)
我想对每个数据包进行随机分组。

对ip使用RandIP函数:

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

并为端口创建您自己的:

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