基本信息
源码名称:python自动化SSH脚本
源码大小:0.56KB
文件格式:.py
开发语言:Python
更新时间:2025-02-05
   源码介绍

用于SSH连接常见网络设备

import paramiko
import time
from getpass import getpass

ip = '10.1.1.3'
user = input('请输入用户名:')
password = getpass('请输入R3的密码:')

ssh_c = paramiko.SSHClient()
ssh_c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_c.connect(hostname = ip,port = 22 , username = user , password = password,look_for_keys=False )

print('成功连接交换机' ip)
cmd = ssh_c.invoke_shell()
file = open('command.txt','r')
for f in file.readlines():
    cmd.send(f)
    time.sleep(1)
file.close()
ssh_c.close()
output = cmd.recv(65535)
print(output.decode())