An attempt at adding UDP support to aiosocks. Untested due to lack of server support.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 lines
609 B

  1. import asyncio
  2. import socket
  3. import functools
  4. def find_unused_port():
  5. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  6. s.bind(('127.0.0.1', 0))
  7. port = s.getsockname()[1]
  8. s.close()
  9. return port
  10. @asyncio.coroutine
  11. def socks_handler(reader, writer, write_buff):
  12. writer.write(write_buff)
  13. @asyncio.coroutine
  14. def fake_socks_srv(loop, write_buff):
  15. port = find_unused_port()
  16. handler = functools.partial(socks_handler, write_buff=write_buff)
  17. srv = yield from asyncio.start_server(
  18. handler, '127.0.0.1', port, family=socket.AF_INET, loop=loop)
  19. return srv, port