1

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:

  1. I use tcpreplay in terminal to replay udp packets on a specific network interface (sudo tcpreplay --pps=75 --intf1=eth0 file.pcapng)

  2. 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'

Pravash Panigrahi
  • 701
  • 2
  • 7
  • 21
zazmi
  • 11
  • 1
  • Does this answer your question? [How to send UDP packet to specific UDP dst port in scapy?](https://stackoverflow.com/questions/28598330/how-to-send-udp-packet-to-specific-udp-dst-port-in-scapy) – Itération 122442 Aug 11 '23 at 07:06
  • I was looking at that too, but I wasn't sure how to fit that in as I already have a packet that I am capturing. "send(IP(dst="127.0.0.1")/UDP(dport=123)/Raw(load="abc"))" is the load where I put in the packet I capture? And also how would I receive that packet on the receiver computer? – zazmi Aug 11 '23 at 17:14
  • Actually that link helped, it worked for me. Thank you! – zazmi Aug 14 '23 at 17:04

0 Answers0