我需要从Cisco的多个节点获取SSH横幅。让我们将其命名为ABC-ACI-APC-01,配置了IP地址10.1.1.1。
假设从10.1.1.2开始到10.1.1.50,这个ACI中有50个IP地址可用。
我可以手动这样一个一个地得到设备的SSH横幅。但考虑到我拥有的设备数量,这并不是最好的解决方案。
ABC-ACI-APC-01# ssh admin@10.1.1.1
=======================================================================
UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED
You must have explicit, authorized permission to access or configure
this device.
Unauthorized attempts and actions to access or use this system may
result in civil and/or criminal penalties.
All activities performed on this device are logged and monitored.
=======================================================================
Password:
Last login: Thu Mar 19 07:56:09 2020 from 10.1.1.254
Cisco Nexus Operating System (NX-OS) Software
XYZ_ACI_LEF_01#
XYZ_ACI_LEF_01# vsh_lc
vsh_lc_ro
module-1# show clock
11:14:57.091 UTC Mon Mar 23 2020
module-1#
module-1# exit
XYZ_ACI_LEF_01#再次,重复这个过程。
看看节点的数量,是否可以将其自动化?
在这种情况下,有什么样例脚本可以从思科ACI ( ABC-ACI-APC-01 )使用并运行吗?
我想要做的是从文件中读取IP列表,比如说ip.txt
执行SSH,进入,并运行额外的命令,即vsh_lc,然后是显示时钟。
然后,退出并再次重复相同的过程。
发布于 2020-03-24 10:46:09
您可以使用ACI的"fabric“命令从APIC中执行此操作。
该命令可以接收要执行的fabric节点‘d列表和show命令。例如-
aci1-apic-1# fabric 1001-1002 show clock
----------------------------------------------------------------
Node 1001 (aci1-lfn-1001)
----------------------------------------------------------------
05:44:38.270483 CDT Tue Mar 24 2020
----------------------------------------------------------------
Node 1002 (aci1-lfn-1002)
----------------------------------------------------------------
05:43:27.153242 CDT Tue Mar 24 2020发布于 2020-06-23 19:01:36
您可以使用以下代码:
#显示运行-config\ egrep“横幅”
此命令将返回APIC的横幅配置。您可以使用字符串来分割不必要的部分并获得横幅。
from netmiko import ConnectHandler
#As mentioned you have a list of devices
ip_list=["<ip_address1>","<ip_address2>","<ip_address3>"]#put all ip addresses in this list
u_name="<username>"
pwd="<password>"
#Run a for loop to access each device
for ip in ip_list:
cred={'device_type':'cisco_nxos',
'ip':ip,
'username':u_name,
'password':pwd}
try:
net_connect=ConnectHandler(**cred)
print("Login Successful")
output=net_connect.send_command('show running-config | grep "banner"')
print(output)
except Exception as e:
print("Login Fail to Device:"+ip)https://networkengineering.stackexchange.com/questions/65779
复制相似问题