async def run(self, **kwargs): lcs = {"context": self.context} async def interact(connection=None): global_dict = {**globals(), "print": print_formatted_text} await embed(return_asyncio_coroutine=True, globals=global_dict, locals=lcs) port = kwargs.get("port", 23) host = kwargs.get("host", "127.0.0.1") telnet_server = TelnetServer(interact=interact, port=port, host=host) stop_event = asyncio.Event(loop=self.context.loop) async def stop(**kwargs): if not stop_event.is_set(): try: await telnet_server.stop() finally: stop_event.set() for sig in ("SIGINT", "SIGTERM"): await self.context.add_signal_handler(sig, stop) telnet_server.start() await stop_event.wait()
async def main(ssh_port=8022, telnet_port=8023): ssh_server = PromptToolkitSSHServer(interact=interact) await asyncssh.create_server( lambda: ssh_server, "", ssh_port, server_host_keys=[ensure_key()] ) print(f"Running ssh server on port {ssh_port}...") telnet_server = TelnetServer(interact=interact, port=telnet_port) telnet_server.start() print(f"Running telnet server on port {telnet_port}...") while True: await asyncio.sleep(60)
def main(): server = TelnetServer(interact=interact, port=2323) server.start() get_event_loop().run_forever()