I've been stuck on this for a few days. What I am trying to do is capture udp packets from a network interface, and then send those captured udp packets to another computer, and then finally write it to a pcap file. I am a bit lost on writing a python script that can receive the UDP traffic.
My set up is this:
I use tcpreplay in terminal to replay udp packets on a specific network interface (
sudo tcpreplay --pps=75 --intf1=eth0 file.pcapng
)I wrote a python script that would capture data using scapy.
I am using two computers - one of them is transmiting data while the other is receiving the data. One of the computers runs linux(Reciving Computer), and the other computer I am using is windows 11 which I am running wsl2 on(Transmitting). Both computers are connected to my phone's hotspot.
This is the code I have for capturing and transmitting data. How would I send the UDP data I have captured?
`from scapy.all import *
from scapy.layers.inet import UDP
packets = sniff(iface="eth0", timeout = 35)
print("scanning")
print(len(packets))
UDP_IP = "192.168.115.186"
UDP_PORT = 5005
for pkt in packets:
//This is where I want to send the packets`
I've been stuck on this for a while and appreciate any tips you all have. Also I am open to using other libraries as well if theres one thats better to use than scapy.
For sending the data, I tried importing socket and doing
from scapy.all import *
from scapy.layers.inet import UDP
import socket
packets = sniff(iface="eth0", timeout = 35)
print("scanning")
print(len(packets))
UDP_IP = "192.168.115.186"
UDP_PORT = 5005
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
for pkt in packets:
sock.sendto(pkt, (UDP_IP, UDP_PORT))
but I get a error:
typeerror: bytes like object is required, not 'Ether'