网络工程师的python之路01

一、配置流程:

1.华为交换机配置:

aaa
 local-user admin password cipher Huawei@123
 local-user admin privilege level 15
 local-user admin service-type ssh

stelnet server enable                     
ssh user admin                            
ssh user admin authentication-type all    
ssh user admin service-type all      

user-interface vty 0 4                    
 authentication-mode aaa                  
 user privilege level 15                  
 protocol inbound all   

2. pycharm代码编写:

//引入第三方模块
import paramiko
import time

//创建变量
ip = "192.168.126.12"
username = "admin"
password = "Huawei@123"

//使用第三方模块登录交换机cli界面
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
ssh_client.connect(hostname=ip, username=username, password=password, look_for_keys=False)
command = ssh_client.invoke_shell()
print("已成功登录交换机" + ip)

//在登录后的cli界面执行命令
command.send("sys\n")
command.send("sysname shiyan01\n")
command.send("interface loopback0\n")
command.send("ip address 1.1.1.1 32\n")
command.send("quit\nquit\n")
time.sleep(5)

//输出并打印回显信息
output = command.recv(65535).decode() 
print(output)

//关闭ssh连接
ssh_client.close()

二、配置结果查看

1.交换机配置结果:

[shiyan01]dis ip in b
[shiyan01]dis ip in brief 
*down: administratively down
^down: standby
(l): loopback
(s): spoofing
The number of interface that is UP in Physical is 3
The number of interface that is DOWN in Physical is 1
The number of interface that is UP in Protocol is 3
The number of interface that is DOWN in Protocol is 1

Interface                         IP Address/Mask      Physical   Protocol  
LoopBack0                         1.1.1.1/32           up         up(s)     
MEth0/0/1                         unassigned           down       down      
NULL0                             unassigned           up         up(s)     
Vlanif1                           192.168.126.12/24    up         up   

2.pycharm回显结果:

C:\Users\17855\PycharmProjects\Network_shiyan\.venv\Scripts\python.exe C:\Users\17855\PycharmProjects\Network_shiyan\shiyan_01.py 
已成功登录交换机192.168.126.12

Info: The max number of VTY users is 5, and the number
      of current VTY users on line is 2.
      The current login time is 2024-05-31 12:18:05.
<shiyan01interface loopback0>sys
Enter system view, return user view with Ctrl+Z.
[shiyan01interface loopback0]sysname shiyan01
[shiyan01]interface loopback0
[shiyan01-LoopBack0]ip address 1.1.1.1 32
[shiyan01-LoopBack0]quit
[shiyan01]quit
<shiyan01>

Process finished with exit code 0

 源学习视频链接:《网络工程师的Python之路》 -- 第1期:初探Paramiko_哔哩哔哩_bilibili

感谢原作者的视频学习,本文章栏目是个人按学习视频学习记录的过程

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值