From 51bd6055a7f648b20e8c2424db8332667fcfa860 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Thu, 5 Dec 2019 23:11:43 -0800 Subject: [PATCH] some test programs to see if a socks server can handle UDP neither SSH (immediate close) NOR tor (bad command) handle UDP --- tests/test_datagram.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/test_datagram.py diff --git a/tests/test_datagram.py b/tests/test_datagram.py new file mode 100644 index 0000000..1069a79 --- /dev/null +++ b/tests/test_datagram.py @@ -0,0 +1,49 @@ +import aiosocks +import asyncio +from tests.test_functional import with_timeout + +machip = '192.168.0.29' +socksport = 2345 +targport = 20834 + +@with_timeout(2) +async def xtest_live_datagram(): + loop = asyncio.get_event_loop() + addr = aiosocks.Socks5Addr('127.0.0.1', socksport) + + dst = (machip, targport) + dgram = await aiosocks.open_datagram(addr, None, dst, loop=loop) + + dgram.send('this is a test\r\n') + +import socket + +def xtest_simpletcp(): + s = socket.socket() + s.connect(('127.0.0.1', socksport)) + + s.send(b'\x05\x01\x00') + assert s.recv(2) == b'\x05\x00' + + s.send(b'\x05\x01\x00\x01' + socket.inet_pton(socket.AF_INET, machip) + (targport).to_bytes(2, 'big')) + + assert s.recv(4) == b'\x05\x00\x00\x01' + print(socket.inet_ntop(socket.AF_INET, s.recv(4)), ':', int.from_bytes(s.recv(2), 'big')) + + s.send(b'foobar\r\n') + +def xtest_simpleudp(): + s = socket.socket() + s.connect(('127.0.0.1', socksport)) + + s.send(b'\x05\x01\x00') + assert s.recv(2) == b'\x05\x00' + + s.send(b'\x05\x03\x00\x01' + socket.inet_pton(socket.AF_INET, machip) + (53).to_bytes(2, 'big')) + print('a') + + assert s.recv(4) == b'\x05\x00\x00\x01' + print('a') + print(socket.inet_ntop(socket.AF_INET, s.recv(4)), ':', int.from_bytes(s.recv(2), 'big')) + print('a') + assert False