forward UDP packets to different IP with scapy

1.2k Views Asked by At

I want to send the captured packets to another PC in my local network. When I run it I keep getting the Output:

Sent 1 packets.

Over and over, but in Wireshark I dont see any packets going to the IP-Adress 192.168.0.5... Not sure what is wrong.

#!/usr/bin/env python3
from scapy.all import sniff, send

def spoof_and_send(packet):
    packet[0][1].dst = '192.168.0.5'
    send(packet)

packets = sniff(filter='udp and portrange 6000-7999', prn=spoof_and_send)
1

There are 1 best solutions below

0
On

You cannot use the original Ethernet header:

def spoof_and_send(packet):
    datagram = packet[IP]
    datagram.dst = "192.168.0.5"
    send(packet)

Moreover, if you use this code you are going to receive the packets you create. You need to filter those out to avoid loops.