From 0d86194f26f75f56b999df1d305de821e9e92508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Mon, 12 Feb 2024 18:10:09 +0100 Subject: [PATCH] changed the script so that its only interface bound MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- server/artnet_converter.py | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/server/artnet_converter.py b/server/artnet_converter.py index 9822d6e..2606dad 100644 --- a/server/artnet_converter.py +++ b/server/artnet_converter.py @@ -1,17 +1,28 @@ -from scapy.all import * -from scapy.arch import get_if_addr +import socket -def forward_artnet(pkt): - # Check if the packet is an ArtNet packet - if pkt.haslayer(IP) and pkt.haslayer(UDP) and pkt[UDP].dport == 6454: - # Check the source IP address and interface - 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") +def forward_artnet(iface_in, iface_out): + # Create raw socket to receive and send ArtNet packets + sock_in = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003)) + sock_in.bind((iface_in, 0)) -# Sniff ArtNet packets on eth0 -while True: - sniff(iface="eth0", prn=forward_artnet, store=0) \ No newline at end of file + sock_out = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003)) + sock_out.bind((iface_out, 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)