0

I need to get SSH banner from bunch of nodes from Cisco ACI. Let's name it as ABC-ACI-APC-01 configured with IP Address 10.1.1.1.

Let say there are 50 IP Addresses available in this ACI started from 10.1.1.2 till 10.1.1.50

I can SSH manually one by one like this to get the device's SSH banner. But this is not the best solution considering the number of devices that I have.

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#

SSH again, repeat the process.

Looking at the number of nodes, would it be possible to automate this?

Is there any sample script I can use and run it from Cisco ACI which is ABC-ACI-APC-01 in this case?

What I want to do is to read the IP list from file, let say ip.txt

Perform the SSH, get in, and run additional command which is vsh_lc, followed by show clock.

Then, exit and repeat the same process again.

7
  • 1
    You could create a TCL script. What is it you want to accomplish with this? There may be a better way to accomplish it.
    – Ron Maupin
    Mar 23 '20 at 14:45
  • Thanks @RonMaupin. I just want to get the SSH banner (MOTD) from each host 10.1.1.2 till 10.1.1.50 and the script needs to be run from the ACI itself 10.1.1.1. Mar 23 '20 at 14:47
  • 1
    Just build a TCL script to do that, but the question is why do you want to do that?
    – Ron Maupin
    Mar 23 '20 at 14:49
  • To automate the manual process. Instead of SSH one by one, it's nice to have a script to help. Mar 23 '20 at 14:53
  • 1
    I'm still not sure why you even want to do this in the first place. If you can explain that, we may be able to give you a better alternative. This sounds like an X-Y Problem.
    – Ron Maupin
    Mar 23 '20 at 15:03
1

You can do this from the APIC using the "fabric" command of the ACI shell.

The command can take a list of fabric node IDs and a show command that you'd like to execute. E.g. -

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
0

You can use the below-mentioned code:

#show running-config | egrep "banner"

This command will return a banner configuration of APIC. You can play with strings to slice out the unnecessary part and get the banner.

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.