bta-proxy/bta_proxy/__main__.py

28 lines
712 B
Python
Raw Normal View History

2023-08-25 21:49:10 +03:00
# x-run: cd .. && python -m bta_proxy '201:4f8c:4ea:0:71ec:6d7:6f1b:a4f9'
2023-08-24 15:29:57 +03:00
import asyncio
2023-08-25 21:49:10 +03:00
from argparse import ArgumentParser
from sys import argv
2023-08-24 15:29:57 +03:00
2023-08-25 21:49:10 +03:00
from bta_proxy.proxy import BTAProxy
2023-08-24 15:29:57 +03:00
MAX_SIZE = 0x400000
2023-08-25 21:49:10 +03:00
2023-08-26 12:33:31 +03:00
async def main(args: list[str]):
2023-08-25 21:49:10 +03:00
loop = asyncio.get_running_loop()
2023-08-26 12:33:31 +03:00
port: int = 25565
if len(args) >= 2:
port = int(args[1])
server = await asyncio.start_server(BTAProxy(args[0], port, loop).handle_client, "localhost", 25565)
print("listening on", str.join(", ", [str(s.getsockname()) for s in server.sockets]))
print("forwarding to", args[0], port)
2023-08-25 21:49:10 +03:00
async with server:
await server.serve_forever()
2023-08-24 15:29:57 +03:00
if __name__ == '__main__':
2023-08-25 21:49:10 +03:00
asyncio.run(main(argv[1:]))