bta-proxy/bta_proxy/__main__.py

28 lines
1020 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-09-04 22:03:31 +03:00
from argparse import ArgumentParser, Namespace
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
2023-09-04 22:03:31 +03:00
parser = ArgumentParser("bta_proxy", description="Better Than Adventure proxy with Deep Packet Inspection")
2023-08-24 15:29:57 +03:00
2023-09-04 22:03:31 +03:00
parser.add_argument("remote_host", type=str)
parser.add_argument("remote_port", type=int, default=25565)
parser.add_argument("--bind", type=str, default="127.0.0.1")
parser.add_argument("--bind-port", type=int, default=25565)
2023-08-25 21:49:10 +03:00
2023-09-04 22:03:31 +03:00
async def main(args: Namespace):
2023-08-25 21:49:10 +03:00
loop = asyncio.get_running_loop()
2023-09-04 22:03:31 +03:00
proxy = BTAProxy(args.remote_host, args.remote_port, loop)
server = await asyncio.start_server(proxy.handle_client, args.bind, args.bind_port)
2023-08-26 12:33:31 +03:00
print("listening on", str.join(", ", [str(s.getsockname()) for s in server.sockets]))
2023-09-04 22:03:31 +03:00
print("forwarding to", args.remote_host, args.remote_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-09-04 22:03:31 +03:00
asyncio.run(main(parser.parse_args()))