1 Star 0 Fork 5

Dawn/计算机网络综合实训拓扑及文件及代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
4.py 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
chensong 提交于 2022-03-28 14:03 . python网络运维部分的代码
import paramiko
import time
ips = ["192.168.99.100" ,"10.110.111.17","10.110.111.22","10.110.111.26","10.110.110.190","10.110.110.125", "10.110.110.126", "10.110.110.254", "10.110.111.14"]
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for ip in ips:
ssh_client.connect(hostname=ip, username="huawei", password="123456")
cmd = ssh_client.invoke_shell()
cmd.send("dis version\n")
time.sleep(1)
jieguo = cmd.recv(10000)
jieguo = jieguo.decode("utf-8")
print(jieguo)
str_name = jieguo.splitlines()[-1][1:-1]
str_name = str_name + "-test99" #改为自己的姓名和学号后两位
cmd.send("sys\n")
cmd.send("sysname " + str_name + "\n")
cmd.send("quit\n")
cmd.send("save\n")
time.sleep(1)
cmd.send("Y\n")
time.sleep(2)
jieguo = cmd.recv(10000)
jieguo = jieguo.decode("utf-8")
print(jieguo)
'''
lines = jieguo.splitlines()
for l in lines:
if l.find("sysname ") >=0:
l = l.strip()
words = l.split(" ")
name = words[1]
name = name + "-chenjg99" #改为自己的姓名和学号后两位
print(name)
cmd.send("sys\n")
cmd.send("sysname " + name + "\n")
cmd.send("quit\n")
cmd.send("save\n")
time.sleep(1)
cmd.send("Y\n")
time.sleep(1)
break
'''
ssh_client.close()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Dawn_Newbie/ensp-python.git
git@gitee.com:Dawn_Newbie/ensp-python.git
Dawn_Newbie
ensp-python
计算机网络综合实训拓扑及文件及代码
master

搜索帮助