栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

实验1 修改loopback0地址

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

实验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("sysn")
command.send("interface LoopBack 0n")
command.send("ip address 1.1.1.1 255.255.255.255n")
command.send("returnn")
command.send("saven")
command.send("yn")
time.sleep(3)
command.send("display thisn")
time.sleep(1)
output = command.recv(65535)
print(output.decode("ascii"))
ssh_client.close()

输出

C:Users82127.condaenvspythonProjectpython.exe E:logpythonpythonProjectDemo01.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.
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
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 ).

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/945680.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号