changed the script so that its only interface bound

Signed-off-by: Ebbe Baß <ebbe.bass>
main
Ebbe Baß 2024-02-12 18:10:09 +01:00
parent 9c8031c47a
commit 0d86194f26
1 changed files with 26 additions and 15 deletions

View File

@ -1,17 +1,28 @@
from scapy.all import * import socket
from scapy.arch import get_if_addr
def forward_artnet(pkt): def forward_artnet(iface_in, iface_out):
# Check if the packet is an ArtNet packet # Create raw socket to receive and send ArtNet packets
if pkt.haslayer(IP) and pkt.haslayer(UDP) and pkt[UDP].dport == 6454: sock_in = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
# Check the source IP address and interface sock_in.bind((iface_in, 0))
if pkt[IP].src.startswith("10.0.") and pkt.route()[0] == "eth0":
# Modify the source IP address to the new network
pkt[IP].src = get_if_addr("wlan0")
# Forward the packet to the new network
send(pkt, iface="wlan0")
print("Forwarded ArtNet packet from eth0 to wlan0")
# Sniff ArtNet packets on eth0 sock_out = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
while True: sock_out.bind((iface_out, 0))
sniff(iface="eth0", prn=forward_artnet, store=0)
while True:
# Receive ArtNet packet from the input interface
pkt, _ = sock_in.recvfrom(65535)
# Modify the source MAC address if needed
# Modify other fields as required
# Forward the packet to the output interface
sock_out.sendall(pkt)
print(f"Forwarded ArtNet packet from {iface_in} to {iface_out}")
# Specify the input and output interfaces
input_interface = "eth0"
output_interface = "wlan0"
# Start forwarding ArtNet packets between interfaces
forward_artnet(input_interface, output_interface)