python登录交换机执行命令_利用Python脚本登录交换机实现自动配置备份的方法

主机参考:服务器测评参考推荐网,专注分享服务器优惠信息!如果您想在本站投放您的广告,点此直达!如果您不想付费,您也可以免费投稿您的产品信息,点此直达!联系我们

部分文章发布时间较久远,可能存在未知因素,购买时建议在本博客搜索商家名称,可查看相关文章充分了解商家!若非中文页面可使用谷歌浏览器同步翻译!跑路不诚信商家列表

利用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脚本登录交换机实现自动配置备份的方法大概了解了吗?如果想了解更多,欢迎关注主机参考行业资讯频道哦

What are the methods to automatically configure backup by using Python script to log in switch? Let’s follow Xiaobian to have a look.

1、 Python script

SSH = paramiko. Sshclient(), SSH. Set 58853; missing  host  key  policy (paramiko. Autoaddpolicy()), SSH. Connect (“10. X.x.x”, 22, “user name”, “password”, 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()

After reading the above, do you have a general idea of how to use Python script to log in to the switch to automatically configure the backup? If you want to learn more, please pay attention to the host reference industry information channel

————————————————————–

主机参考,收集国内外VPS,VPS测评,主机测评,云服务器,虚拟主机,独立服务器,国内外服务器,高性价比建站主机相关优惠信息@zhujicankao.com

详细介绍和测评国外VPS主机,云服务器,国外服务器,国外主机的相关优惠信息,商家背景,网络带宽等等,也是目前国内最好的主机云服务器VPS参考测评资讯优惠信息分享平台

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值