温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

利用Python脚本登录交换机实现自动配置备份的方法

发布时间:2020-03-24 11:07:07 来源:亿速云 阅读:1032 作者:小新 栏目:网络管理

利用Python脚本登录交换机实现自动配置备份的方法有哪些?下面跟着小编一起来看看吧。

一、Python脚本

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("10.x.x.x", 22,"用户名","密码",allow_agent=False,look_for_keys=False)

command = 'sh running-config \r '

stdin, stdout, stderr = ssh.exec_command(command)
#stdin, stdout, stderr = ssh.invoke_shell(command)
a=[]
result = stdout.readlines()

if not result:
result = stderr.read()

backup=open("/root/worke/beifen/beifen.txt","w")

for line in result:
print(line)
backup.write(line)

backup.close()
ssh.close()

看完上文,你对利用Python脚本登录交换机实现自动配置备份的方法大概了解了吗?如果想了解更多,欢迎关注亿速云行业资讯频道哦

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI