# -*- coding: UTF-8 -*-
import telnetlib
import time
import datetime
import os
import json Username=
Password=
ip=
enable_passwd=
file='/opt/test.txt' def connect(ip, username, password, enable_passwd):
tn = telnetlib.Telnet(ip.encode('utf-8'))
tn.read_until('Username: ') # 用户名
tn.write(username.encode('utf-8') + '\n')
tn.read_until('Password: ') # 密码
tn.write(password.encode('utf-8') + '\n')
tn.write('enable' + '\n')
tn.read_until('Password: ') #enable 模式
tn.write(enable_passwd.encode('utf-8') + '\n')
if tn.read_until('#'):
tn.write('terminal length 0' + '\n')
print '登录成功'
time.sleep(1)
tn.write('configure terminal' + '\n') # 进入设置模式
time.sleep(1)
return tn def split_res(info):
info = info.strip().split('\r\n')[1:-1]
return '\n'.join(info) def run_command(tn, command):
print '开始执行命令: {}'.format(command)
tn.write(command + '\n')
time.sleep(3)
strs = split_res(tn.read_very_eager())
return strs def main(file):
with open(file[0], 'r') as f:
command_list = f.readlines()
client = connect(ip, Username, Password, enable_passwd)
for lien in command_list:
print lien.split("\n")[0]
res = run_command(client, lien.split("\n")[0]) # 执行配置下发
print res
print "执行完成"
return True if __name__ == '__main__':
main(file)

最新文章

  1. JAVA UUID 生成
  2. Java实现操作dos命令
  3. CSS3与页面布局学习笔记(八)——浏览器兼容性问题与前端性能优化方案
  4. MyBatis学习--简单的增删改查
  5. 找规律 ZOJ3498 Javabeans
  6. 更改Windows系统时间同步频率【windows 7,windows 8,win10】
  7. excel中的单位换算函数convert()
  8. 使用 CocoStudio UI 编辑器实现《乱斗堂》设置界面
  9. JavaSE_ API常用对象 总目录(11~14)
  10. ps遇到的问题及笔记
  11. vm选项大全
  12. centos7.3搭建lamp实现使用wordpress
  13. H5 input输入限制最大位数,和调用小键盘需求发生冲突的解决办法
  14. Eclipse中启动Tomcat报错:[There is insufficient memory for the Java Runtime Environment to continue.]的解决方案
  15. 急速安装lnmp 编译版本-wiki-shell脚本实现一键部署
  16. keepalived+lvs子网掩码造成VIP切换故障 + vrrp_script+track_script
  17. java FindMyIP.java
  18. UnicodeString基本操作(Ring3)
  19. 使用jupyterthemes插件定制jupyter notebook界面
  20. LGWR和DBWn的触发条件

热门文章

  1. Docker 对于容器的增删查命令
  2. echart地图引入路径问题
  3. SimplCommerce 核心
  4. 我的vim配置相关
  5. TypeScript 学习之路
  6. C#中定时任务被阻塞问题
  7. 第十章用Python获取sqlite、MySQL、Excel、csv、json中的数据
  8. anaconda新建的虚拟环境更改默认位置
  9. VMware导入ovf报错
  10. CB9328是一颗PA+LNA+Switch三合一的FEM 兼容S*8112Q