|
First of all, many thanks to all the contributors of asyncssh. def server_requested(self, listen_host: str, listen_port: int) -> _NewListener:
return TrueAnd using: ssh -p 8022 -R 0:localhost:8000 guest@localhostHowever, I would like to know which IPs have accessed which resources on localhost:8000, in order to implement monitoring or capture logs. Can this feature be directly implemented using asyncssh? |
Replies: 2 comments 4 replies
|
It doesn't look like this is possible in AsyncSSH right now using only public APIs. You'd need to be able to provide an alternate coroutine which runs when a connection is received on the listening port. The closest I think you can come right now is: class MySSHServer(asyncssh.SSHServer):
async def forward_local_port(self, listen_host, listen_port):
async def tunnel_connection(session_factory, orig_host, orig_port):
print(f'New connection from {orig_host}:{orig_port}')
return await self._conn.create_connection(
session_factory, listen_host, listen_port, orig_host, orig_port)
loop = asyncio.get_event_loop()
return await create_tcp_forward_listener(
self._conn, loop, tunnel_connection, listen_host, listen_port)
def connection_made(self, conn):
self._conn = conn
def server_requested(self, listen_host, listen_port):
return self.forward_local_port(listen_host, listen_port)
async def start_server():
await asyncssh.create_server(MySSHServer, '', 8022,
server_host_keys=['ssh_host_key'],
authorized_client_keys='ssh_user_ca')
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(start_server())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH server failed: ' + str(exc))
loop.run_forever()In particular, see how the Unfortunately, the function Since |
|
This feature is now checked into the "develop" branch as commit 70f65eb. For now, this new accept_handler is available in |
It doesn't look like this is possible in AsyncSSH right now using only public APIs. You'd need to be able to provide an alternate coroutine which runs when a connection is received on the listening port. The closest I think you can come right now is: