import paramiko
def rcmd(host, username, password, commands):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(
paramiko.AutoAddPolicy()
)
ssh.connect(host,
username=username, password=password)
data = ssh.exec_command(commands)
log = data[1].read()
err = data[2].read()
if len(log) !=0:
print("log:", log.decode(), end="")
if len(err) !=0:
print("err:", err.decode(), end="")
ssh.close()
if __name__ == '__main__':
ip = input("请输入您要操作的远程主机ip:")
username = input(f"请输入IP为:{ip}, 登录的用户名:")
password = input(f"请输入{username}对应的密码:")
cmds = input("请输入要执行的命令:")
rcmd(ip, username, password, cmds)