python自动化控制设备有限公司_华为 Python网络自动化
哈喽,大家好!我是艺博东 ,是一个思科出身、专注于华为的网工;好了,话不多说,我们直接进入正题。
光棍二十年,不知道情人节是什么鬼东西。还是好好学技术吧!努力、奋斗吧!为了早日走向人生巅峰,迎娶白富美!拼了
1、安装环境并导入相关模块
首先是安装好Python3环境,接着安装Paramiko模块,然后输入pip3 install paramiko。
pip3 install paramiko
更新pip
pip install --upgrade pip
OK
进入python,导入 paramiko模块
import paramiko
2、创建VLAN并配置IP地址和路由协议
2.1 拓扑
2.2 简单配置与测试
SW1
[Huawei]sysname SW1
[SW1]vlan 100
[SW1-vlan100]q
[SW1]int Vlanif 100
[SW1-Vlanif100]ip address 192.168.117.254 24
[SW1-Vlanif100]int g0/0/1
[SW1-GigabitEthernet0/0/1]p l a
[SW1-GigabitEthernet0/0/1]p d v 100
[SW1-GigabitEthernet0/0/1]q
[SW1]user-interface vty 0 4
[SW1-ui-vty0-4]authentication-mode aaa
[SW1-ui-vty0-4]protocol inbound ssh
[SW1-ui-vty0-4]q
[SW1]aaa
[SW1-aaa]local-user ybd password cipher 1008611
[SW1-aaa]local-user ybd privilege level 15
[SW1-aaa]local-user ybd service-type ssh
[SW1-aaa]q
[SW1]ssh user ybd authentication-type password
[SW1]ssh user ybd service-type stelnet
[SW1]stelnet server enable
eNSP路由器AR1的PING测试物理机
[SW1]ping 192.168.117.1
物理机PING测试eNSP路由器AR1
注意:做桥记得关闭防火墙,否则eNSP PING测不通物理机。
2.3 python脚本
import paramiko
import time
ip = "192.168.117.254" #交换机的IP地址
user = "ybd" #SSH的用户名
pw = "1008611" #SSH的密码
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=ip, username=user , password=pw)
print("已成功登录到eNSP上的交换机了!" , ip)
#连接成功后,调用invoke_shell()方法来唤醒shell,也就是华为系统命令行,同时把它赋值给command,方便后续调用。
command = ssh.invoke_shell()
#向设备发送命令,需要执行的命令。
command.send("system \n")
command.send("vlan 120 \n")
command.send("quit \n")
command.send("int vlan 120 \n")
command.send("ip add 192.168.120.1 24 \n")
command.send("quit \n")
command.send("vlan 130\n") #创建vlan 130
command.send("quit \n") #返回上一级
command.send("int vlan 130 \n") #进入vlan 130 视图
command.send("ip add 192.168.130.1 24 \n") #配置IP地址
command.send("quit \n")
command.send("vlan 140\n")
command.send("quit \n")
command.send("int vlan 140 \n")
command.send("ip add 192.168.140.1 24 \n")
command.send("quit \n")
command.send("ospf 1 router-id 1.1.1.1 \n")
command.send("a 0 \n")
command.send("net 192.168.0.0 0.0.255.255 \n")
command.send("quit \n")
command.send("quit \n")
command.send("ip route-static 192.168.117.1 32 NULL 0 \n")
command.send("ospf 1 \n")
command.send("import-route static \n")
#使用sleep函数,让脚步执行后休息2s,再回显内容。65535是回显多少个字符
time.sleep(3)
output = command.recv(65535)
print(output.decode("ascii"))
ssh.close() #配置完后,用close方法退出ssh
运行结果:
[SW1]display ip int brief
已OK
3、telnet 远程登录管理设备
3.1 拓扑
3.2 简单配置与测试
AR1
[Huawei]sysname AR1
[AR1]int g0/0/0
[AR1-GigabitEthernet0/0/0]ip address 192.168.150.254 24
[AR1-GigabitEthernet0/0/0]q
[AR1]user-interface vty 0 4
[AR1-ui-vty0-4]authentication-mode password
Please configure the login password (maximum length 16):1008611
[AR1-ui-vty0-4]protocol inbound telnet
[AR1-ui-vty0-4]user privilege level 15
[AR1-ui-vty0-4]q
eNSP路由器AR1的PING测试物理机
[AR1]ping 192.168.150.1
物理机PING测试eNSP路由器AR1
3.3 python脚本
import telnetlib
import time
host ='192.168.150.254'
password='1008611'
_UserTag = '>'
_SysTag = ']'
tn = telnetlib.Telnet(host)
tn.read_until(b'Password:')
tn.write(password.encode('ascii') + b"\n")
UserTag = tn.read_until(_UserTag.encode('ascii'))
response = UserTag
print(response.decode('ascii'))
time.sleep(2)
tn.write(b"dir\n")
response = UserTag
if b'>' in response:
print(response.decode('ascii'))
time.sleep(2)
tn.write(b"system-view\n")
SysTag = tn.read_until(_SysTag.encode('ascii'))
response = SysTag
print(response.decode('ascii'))
time.sleep(2)
tn.close()
print("close")
运行结果:
困难越大,荣耀也越大。——西塞罗
好了这期就到这里了,如果你喜欢这篇文章的话,请点赞评论分享收藏,如果你还能点击关注,那真的是对我最大的鼓励。谢谢大家,下期见!
python自动化控制设备有限公司_华为 Python网络自动化相关推荐
- python语音控制电脑程序_用Python编程实现语音控制电脑_天津SEO
天津SEO 电脑面前的你,是否也希望能让电脑听命于你? 当你累的时候,只需说一声"我累了",电脑就会放着优雅的轻音乐来让你放松. 或许你希望你在百忙之中,能让电脑郎读最新的NBA比 ...
- 全球与中国水电站自动化控制设备市场现状及未来发展趋势
水电站自动化控制设备是集计算机监控.数据采集与处理.顺序控制.励磁.调速.自动准同期.测速.功率调节.水机及电气保护等多项功能为一体的综合发电控制装置,从而提高电能质量和发电效率 2020年,全球水电 ...
- 可靠性测试设备技术含量_电气自动化控制设备的可靠性测试(1)
龙源期刊网 http://www.qikan.com.cn 电气自动化控制设备的可靠性测试 作者:彭波 来源:<消费电子 · 理论版> 2013 年第 10 期 摘 要:近年来电气自动化控 ...
- python交互式和文件式_使用Python创建和自动化交互式仪表盘
python交互式和文件式 In this tutorial, I will be creating an automated, interactive dashboard of Texas COVI ...
- python文本结构化处理_在Python中标记非结构化文本数据
python文本结构化处理 Labelled data has been a crucial demand for supervised machine learning leading to a n ...
- python做审计底稿视频_最新Python教学视频,每天自学俩小时,让你offer拿到手软...
2020最新Python零基础到精通资料教材,干货分享,新基础Python教材,看这里,这里有你想要的所有资源哦,最强笔记,教你怎么入门提升!让你对自己更加有信心,重点是资料都是免费的,免费!!! 如 ...
- python机器人编程与操作_机器人Python极客编程入门与实战 PDF 完整目录版
给大家带来的一篇关于Python编程相关的电子书资源,介绍了关于机器人.Python.极客编程.入门.实战方面的内容,本书是由电子工业出版社出版,格式为PDF,资源大小25.8MB,Python极客团 ...
- python怎么做软件程序_看 Python 超级程序员使用什么开发工具
Python超级程序员使用的开发工具 我以个人的身份采访了几个顶尖的Python程序员,问了他们以下5个简单的问题: 当前你的主要开发任务是什么? 你在项目中使用的电脑是怎样的? 你使用什么IDE开发 ...
- 学python编程好就业吗_自学Python编程开发靠谱吗 就业前景怎么样
人工智能行业学习Python编程到底有多么重要,新人在学习Python的时候改如何选择,就业方向有哪些?想要了解这些,现在我们今天就来看看Python的主要开发领域以及每个岗位对应的薪资. Pytho ...
最新文章
- 使数组中奇数位于偶数前面
- anaconda在ubuntu中安装后没有_你的大数据平台中病毒了!!!记一次HDP安装后中dr.who病毒并修复的过程...
- Vuex——命名空间导致错误[unknown action type:XXX]解决方案
- Qt Creator填写代码
- 一个简单的内存分配例子
- 尝试使用jBPM Console NG(测试版)
- 连接 Microsoft Cloud App Security 的数据
- (需求实战_03) SpringBoot整合RabbitMQ 关键代码、策略、模式讲解
- Kafka集群部署CentOS 7
- 三、处理机调度与死锁
- 二叉树的层次遍历II
- Event Grid更新了!可轻松处理物联网装置遥测
- MySQL 5.7.27 MGR 单主/多主+ ProxySQL
- 使用Typora绘制流程图
- 【答题卡识别】基于matlab GUI hough变换答题卡成绩统计(带面板)【含Matlab源码 1828期】
- Highlighting高亮插件使用说明
- python — pip 下载速度慢解决方法(含Anaconda、spyder 下载包的方法)
- ab网站压力测试命令的参数、输出结果的中文注解
- 《游戏制作人手册》读书笔记
- linux rpm 装 mac,linux之 rpm,yum
热门文章
- 启动马达接线实物图_电工外出接单从事配电柜接线、调试工作的三个要领
- linux lanmp 安装教程,Linux 安装 lanmp
- mysql注册slave_创建slave库?spm=a2c4e.11155472的搜索结果-阿里云开发者社区
- 职高一年级计算机阶段考试,2012上期职高一年级计算机专业期末考试题.doc
- android onclick方法吗,Android中button的onClick事件几种方法
- php cdr,win10彻底禁止cdr联网
- 数学建模学习笔记(十一)——预测模型
- java递归栈_java-66-用递归颠倒一个栈。例如输入栈{1,2,3,4,5},1在栈顶。颠倒之后的栈为{5,4,3,2,1},5处在栈顶...
- 国产自主可控的嵌入式仿真软件SkyEye和同步数据流语言高阶运算消去的可信翻译
- 中countif函数_Count系列函数-Count、Counta、Countblank、Countif、Countifs