Created
November 8, 2018 19:42
-
-
Save elazarl/6650fca2655590378a1b9c8a5c9f8334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import argparse | |
import paramiko.client | |
import time | |
parser = argparse.ArgumentParser(description='stress test SSH channels') | |
parser.add_argument('-H', '--host', help='host to test') | |
parser.add_argument('-u', '--user', help='user to use SSH with') | |
parser.add_argument('-p', '--pwd', help='password to use SSH with') | |
parser.add_argument( | |
'-P', '--port', type=int, default=22, help='SSH port to use') | |
parser.add_argument( | |
'-N', | |
'--num-channels', | |
type=int, | |
default=22, | |
help='password to use SSH with') | |
args = parser.parse_args() | |
def main(): | |
c = paramiko.client.SSHClient() | |
c.set_missing_host_key_policy(paramiko.client.WarningPolicy) | |
c.connect( | |
args.host, | |
port=args.port, | |
username=args.user, | |
password=args.pwd, | |
look_for_keys=False, | |
allow_agent=False) | |
sessions = [] | |
for i in range(args.num_channels): | |
sessions.append(c._transport.open_session()) | |
for s in sessions: | |
s._event_pending() | |
s.transport._send_user_message(make_exec_msg(s, "hostname")) | |
time.sleep(3) | |
for s in sessions: | |
s._wait_for_event() | |
def make_exec_msg(chan, cmd): | |
m = paramiko.Message() | |
m.add_byte(paramiko.common.cMSG_CHANNEL_REQUEST) | |
m.add_int(chan.remote_chanid) | |
m.add_string("exec") | |
m.add_boolean(True) | |
m.add_string(cmd) | |
return m | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment