Python 实现设备远程命令执行 (system-view, netconf, quit)
import paramiko
创建SSH客户端对象
ssh_client = paramiko.SSHClient()
添加host key
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
连接到目标设备
ssh_client.connect(hostname='192.168.1.1', port=22, username='admin', password='admin')
执行命令:'system-view'
stdin, stdout, stderr = ssh_client.exec_command('system-view')
打印输出结果
print(stdout.read().decode())
执行命令:'netconf'
stdin, stdout, stderr = ssh_client.exec_command('netconf')
打印输出结果
print(stdout.read().decode())
执行命令:'quit'
stdin, stdout, stderr = ssh_client.exec_command('quit')
打印输出结果
print(stdout.read().decode())
关闭SSH连接
ssh_client.close()
原文地址: https://www.cveoy.top/t/topic/n33n 著作权归作者所有。请勿转载和采集!