Skip to content

Can AsyncSSH capture data during port forwarding? #592

Answered by ronf
zgxkbtl asked this question in Q&A
Discussion options

You must be logged in to vote

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 c…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@zgxkbtl
Comment options

@ronf
Comment options

@ronf
Comment options

Answer selected by zgxkbtl
Comment options

You must be logged in to vote
1 reply
@ronf
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants