#!/usr/bin/env python3.9
# --*-- coding:utf-8 --*--
import paramiko
def ssh_client_con(command):
try:
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
ssh_client.connect(
host=host,
port=port,
user=user,
password=password
)
stdin,stdout,stderr = ssh_client.exec_command(comnad)
stdout_info = stdout.read().decode('utf-8')
print(stdout_info)
stderr_info = stderr.read().decode('utf-8')
print(stderr_info)
except Exception as e:
print(e)
try:
with open('/tmp/host.txt','r',encode='utf-8') as host_file:
for host_info in host_file:
line = host_info.strip('\n')
host,port,user,password = line.split(',')
ssh_client_con(command)
except FileNotFoundError as e:
print(e)
if __name__ == '__main__':
ssh_client_con("ls -l")