实验1 修改loopback0地址

实验拓扑

在这里插入图片描述

config:

aaa
local-user python password cipher 123asd
local-user python privilege level 3
local-user python service-type ssh

stelnet server enable
ssh authentication-type default password

user-interface vty 0 4
authentication-mode aaa
protocol inbound ssh
screen-length 0

192.168.8.0/24 ⽹段我⾃⼰的电脑(Win10 已安装 python 3.9.3)设置⼀块虚拟⽹卡地址为 192.168.8.105/24,桥接,与实验拓扑拉通组⽹。
本次实验只需要⽤到 PC ,透明交换机SW1(启动即可,⽆需配置)、LSW1(Python 第三⽅库 paramiko 要操控的设备。),其它 LSW未启动,后续实验再使⽤。
⽤Python Paramiko 模块实现 SSH 登陆单个交换机LSW1(192.168.8.201),为其 LoopBack0 端⼝配置IP地址 1.1.1.1 /32。配置完成后对设备进⾏配置保存,并退出。
检查⽹络连通性(PC ping 测 192.168.201),打开 cmd,执⾏ ping 192.168.8.201
检查 win10 的 arp 表项,打开 cmd ,执⾏ arp -a ,找到 接⼝: 192.168.8.201 — 0x10 查看表项。

import paramiko
import time
ip = "192.168.8.201"
username = "python"
password = "123asd"
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)
print("Successfully connected to ", ip)
command = ssh_client.invoke_shell()
command.send("sys\n")
command.send("interface LoopBack 0\n")
command.send("ip address 1.1.1.1 255.255.255.255\n")
command.send("return\n")
command.send("save\n")
command.send("y\n")
time.sleep(3)
command.send("display this\n")
time.sleep(1)
output = command.recv(65535)
print(output.decode("ascii"))
ssh_client.close()

输出

C:\Users\82127\.conda\envs\pythonProject\python.exe E:\log\python\pythonProject\Demo01.py
Successfully connected to  192.168.8.201

Info: The max number of VTY users is 5, and the number
      of current VTY users on line is 1.
      The current login time is 2022-05-30 22:54:56.
<LSW1>sys
Enter system view, return user view with Ctrl+Z.
[LSW1]interface LoopBack 0
[LSW1-LoopBack0]ip address 1.1.1.1 255.255.255.255
[LSW1-LoopBack0]return
<LSW1>save
The current configuration will be written to the device.
Are you sure to continue?[Y/N]y
Info: Please input the file name ( *.cfg, *.zip ) [vrpcfg.zip]:display this
Error: Invalid file name or Invalid extension ( *.cfg, *.zip ).
<LSW1>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

期待未来的男孩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值