import paramiko
import time
username ='python'
password ='123asd'for i inrange(9,11):
ip ='192.168.1.'+str(i)
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('=-=-=-=-=-=-=-=-=-=-=-=-=-=')print('已经成功登陆交换机 LSW-'+str(i-8)+' '+ ip)# 关闭分屏功能
command.send('screen-length 0 temporary\n')# 进⼊系统视图
command.send('sys\n')
command.send('dis int bri\n')
time.sleep(2)#抓取回显,放⼊output变量
output = command.recv(65535).decode('ASCII')print(output)#保存结果到python脚本同⽬录下的result⽂件夹中
f1 =open(f".\\result\\{ip}_dis_int_bri.txt","w")
f1.write(output)
f1.close()
ssh_client.close()
C:\Users\82127\.conda\envs\pythonProject\python.exe E:/log/python/pythonProject/Demo07.py
=-=-=-=-=-=-=-=-=-=-=-=-=-=
已经成功登陆交换机 LSW-1 192.168.1.9
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-06-04 14:22:57.
<Huawei>screen-length 0 temporary
Info: The configuration takes effect on the current user terminal interface only.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]dis int bri
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
(e): ETHOAM down
(dl): DLDP down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/1 up up 0% 0% 0 0
GigabitEthernet0/0/2 down down 0% 0% 0 0
GigabitEthernet0/0/3 down down 0% 0% 0 0
GigabitEthernet0/0/4 down down 0% 0% 0 0
GigabitEthernet0/0/5 down down 0% 0% 0 0
GigabitEthernet0/0/6 down down 0% 0% 0 0
GigabitEthernet0/0/7 down down 0% 0% 0 0
GigabitEthernet0/0/8 down down 0% 0% 0 0
GigabitEthernet0/0/9 down down 0% 0% 0 0
GigabitEthernet0/0/10 down down 0% 0% 0 0
GigabitEthernet0/0/11 down down 0% 0% 0 0
GigabitEthernet0/0/12 down down 0% 0% 0 0
GigabitEthernet0/0/13 down down 0% 0% 0 0
GigabitEthernet0/0/14 down down 0% 0% 0 0
GigabitEthernet0/0/15 down down 0% 0% 0 0
GigabitEthernet0/0/16 down down 0% 0% 0 0
GigabitEthernet0/0/17 down down 0% 0% 0 0
GigabitEthernet0/0/18 down down 0% 0% 0 0
GigabitEthernet0/0/19 down down 0% 0% 0 0
GigabitEthernet0/0/20 down down 0% 0% 0 0
GigabitEthernet0/0/21 down down 0% 0% 0 0
GigabitEthernet0/0/22 down down 0% 0% 0 0
GigabitEthernet0/0/23 down down 0% 0% 0 0
GigabitEthernet0/0/24 down down 0% 0% 0 0
MEth0/0/1 down down 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0
Vlanif1 up up -- -- 0 0
[Huawei]
=-=-=-=-=-=-=-=-=-=-=-=-=-=
已经成功登陆交换机 LSW-2 192.168.1.10
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-06-04 14:23:00.
<Huawei>screen-length 0 temporary
Info: The configuration takes effect on the current user terminal interface only.
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]dis int bri
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
(e): ETHOAM down
(dl): DLDP down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/1 up up 0% 0% 0 0
GigabitEthernet0/0/2 down down 0% 0% 0 0
GigabitEthernet0/0/3 down down 0% 0% 0 0
GigabitEthernet0/0/4 down down 0% 0% 0 0
GigabitEthernet0/0/5 down down 0% 0% 0 0
GigabitEthernet0/0/6 down down 0% 0% 0 0
GigabitEthernet0/0/7 down down 0% 0% 0 0
GigabitEthernet0/0/8 down down 0% 0% 0 0
GigabitEthernet0/0/9 down down 0% 0% 0 0
GigabitEthernet0/0/10 down down 0% 0% 0 0
GigabitEthernet0/0/11 down down 0% 0% 0 0
GigabitEthernet0/0/12 down down 0% 0% 0 0
GigabitEthernet0/0/13 down down 0% 0% 0 0
GigabitEthernet0/0/14 down down 0% 0% 0 0
GigabitEthernet0/0/15 down down 0% 0% 0 0
GigabitEthernet0/0/16 down down 0% 0% 0 0
GigabitEthernet0/0/17 down down 0% 0% 0 0
GigabitEthernet0/0/18 down down 0% 0% 0 0
GigabitEthernet0/0/19 down down 0% 0% 0 0
GigabitEthernet0/0/20 down down 0% 0% 0 0
GigabitEthernet0/0/21 down down 0% 0% 0 0
GigabitEthernet0/0/22 down down 0% 0% 0 0
GigabitEthernet0/0/23 down down 0% 0% 0 0
GigabitEthernet0/0/24 down down 0% 0% 0 0
MEth0/0/1 down down 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0
Vlanif1 up up -- -- 0 0
[Huawei]
进程已结束,退出代码0