Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio, asyncssh, sys
- class MySSHClientSession(asyncssh.SSHClientSession):
- def data_received(self, data, datatype):
- print(data, end='')
- def connection_lost(self, exc):
- if exc:
- print('SSH session error: ' + str(exc), file=sys.stderr)
- async def run_client(host, cmd):
- conn, client = await asyncssh.create_connection(asyncssh.SSHClient, host)
- async with conn:
- chan, session = await conn.create_session(MySSHClientSession, cmd)
- await chan.wait_closed()
- CMD = "ping %s"
- try:
- asyncio.get_event_loop().run_until_complete(asyncio.gather(
- run_client('localhost', CMD % 'localhost'),
- run_client('localhost', CMD % 'google.com')
- ))
- except (OSError, asyncssh.Error) as exc:
- sys.exit('SSH connection failed: ' + str(exc))
Add Comment
Please, Sign In to add comment