Skip to content

simple python script for saving the output of the current interface status from a list of devices

License

Notifications You must be signed in to change notification settings

jonsch-org/InterStat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

InterStat

Supported devices/OS

Cisco (IOS, IOS-XE, NX-OS)
Dell (FTOS)

What is InterStat?

InterStat is a simple python script for saving the output of the current interface status from a list of devices. It is using the libary paramiko for building up a ssh connection to the network devices (switches, routers,...) which are defined in a list of ip adresses.

After successful connection to a device, the script collect some device informations like check privilege mode, paging, brand, hostname and of course the status of the interfaces. The device information will just printed out to the shell and only the interface status output will be saved to a file named like the hostname of the device.

How to use?

Before you can start the script, maybe you have to change some parameters. There are three variables you have to look for.

1. SSH-Port

By default the ssh port is 22. If you want to take another port for the ssh connection, you have to edit the line 38 which defines the ssh port. Change the 22 to the port you prefer.

port = ('22')

2. Destination path

By default the destination path is G:/InterStat/. Normally you want to costumize the path where the files should be saved. In this reason you have to edit the line 41 which defines the path to the destination directory.

path = (r'G:/InterStat/')

3. IP-List

By default the ip list for the devices is named ip_list. Maybe you want to change the filename. For this case you have to edit the line 44, line 45 and line 57 which defines the ip list.

with open('ip_list.txt', 'r') as ip:
and
ip_list = ip.read().split('\n')
and
for ip in ip_list:

Step by Step

After you changed the parameters and the directories are defined, you can start the script.

  1. First of all you get asked for your credentials to login to the device. There are two options to login. The first credentials you will get asked are your active directory once if you are using RADIUS or any other kind of authentication process. If you are just using local credentials on each device or your active directory login fails, the script will use your local account. If the script can not reach or connect to the device, the destination device will be skipped and the next IP address will be used. If the authentication with AD and local credentials will fail, the script will also skip this IP address and the next one will be used.

  2. After login the script will open in a for loop the ip list and pick the ip address of the first line. In the next step the ssh connection to the device will be build up. The first try of login will be with the active directory credentials and after that with the local credentials.

  3. In the next step the InterStat.py check if you are still in privilege mode, if not the login will be tried with the ena password you defined at the start.

  4. The script will disable the paging function to get the maximum output.

  5. To get the hostname of the device the script will ask the device with the show version command, which brand the device is of. By default the brand could be cisco (IOS, IOS-XE, NX-OS, ...) and dell (Force 10). Depending on which one, the script will prompt the show run | include hostname or show run | find hostname command to pick out the hostname of the device.

  6. After that the main function will start his work. The interface status command will be promt and the output will be saved to a textfile with the hostname fo the device as filename to the directory you defined at the start. If this succeed the script will pick the next ip address of the ip list and repeat the process.

The script will end with the last ip address in the ip list.