Commit 063d7e1c authored by root's avatar root
Browse files

add extensions to udp_proxy and udp_mirror script as proposed by martin froehlich

parent c9440698
......@@ -9,9 +9,9 @@ except ValueError:
sys.exit(1)
# haben wir einen gueltigen Port
if not isinstance( UDP_PORT, int ) or not 4464 <= UDP_PORT <= 4500:
if not isinstance( UDP_PORT, int ) or not 1024 <= UDP_PORT <= 40000:
print 'Specified port (', UDP_PORT, ') is invalid.'
print 'Valid port range: 4464 - 4500'
print 'Valid port range: 1024 - 40000'
sys.exit(1)
# Lass uns die socket erzeugen
......@@ -25,5 +25,5 @@ except socket.error, msg:
addr = None
while True:
data, addr = sock.recvfrom(16400)
data, addr = sock.recvfrom(65536)
sock.sendto(data, addr)
#!/usr/bin/env python
import socket, sys
import socket, sys, thread, time
UDP_IP = "0.0.0.0"
timeout = 10
try:
UDP_PORT = int(sys.argv[1])
except ValueError:
......@@ -9,9 +10,9 @@ except ValueError:
sys.exit(1)
# haben wir einen gueltigen Port
if not isinstance( UDP_PORT, int ) or not 4464 <= UDP_PORT <= 5200:
if not isinstance( UDP_PORT, int ) or not 1024 <= UDP_PORT <= 40000:
print 'Specified port (', UDP_PORT, ') is invalid.'
print 'Valid port range: 4464 - 4500'
print 'Valid port range: 1024 - 40000'
sys.exit(1)
# Lass uns die socket erzeugen
......@@ -25,22 +26,51 @@ except socket.error, msg:
addr = None
client1 = None
client2 = None
stealing = 0
lastCall1 = 0
lastCall2 = 0
while True:
data, addr = sock.recvfrom(16400) # buffer size is 1024 bytes
def save_file():
global client1
global client2
text_file = open("/var/www/html/ports/" + str(UDP_PORT) + ".txt", "w")
text_file.write(str(client1) + " < - > " + str(client2) + "\n")
text_file.close()
# Assigning clients
if addr != client1 and addr != client2:
if stealing == 0:
client1 = addr
else:
def loop(threadName, delay):
global client1
global client2
global lastCall1
global lastCall2
while True:
data, addr = sock.recvfrom(65536)
# Assigning clients
if addr != client1 and addr != client2:
client1 = client2
client2 = addr
stealing = (stealing + 1) % 2
# transmit data
if client1 and client2:
if addr == client1:
sock.sendto(data, client2)
elif addr == client2:
sock.sendto(data, client1)
lastCall2 = time.time()
save_file()
# transmit data
if client1 and client2:
if addr == client1:
sock.sendto(data, client2)
lastCall1 = time.time()
elif addr == client2:
sock.sendto(data, client1)
lastCall2 = time.time()
try:
thread.start_new_thread( loop, ("SenderLoopThrd", 0, ) )
print "started listeing thread"
except:
print "Error: unable to start thread"
while 1:
time.sleep(1)
if client1 != None and (lastCall1 + timeout) < time.time():
client1 = None
save_file()
if client2 != None and (lastCall2 + timeout) < time.time():
client2 = None
save_file()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment