A Python script to capture the running-config of Cisco Routers and Switches.
This script was originally written in Python2 and relied on Exscript to handle the 'heavy lifting' of communicating with the router.
However, in conjunction with updating this code to work with Python3, I've selected NAPALM to replace the functionality that Exscript once provided.
- This application is hard-coded to use the SSH2 protocol; If SSH v2 is not enabled on your router(s), you will need to add
ip ssh version 2
to your Cisco router(s) configuration and any associated access-list changes. - A valid username/password.
- A text file containing hostnames or IP Addresses of your routers/switches, one entry per line.
- This application was written for use on Cisco IOS devices and cannot be guaranteed to work on other makes/model routers.
- This application assumes that you have enable privileges on each router in order to execute the
show running-config
command. If you do not have sufficient user privileges, this application will not work as designed.
- This application uses the same username/password to access ALL routers. If your routers use unique usernames/passwords, then this script will not work. (Yes this is a terrible idea but let's not pretend it's not like this at many companies.)
- See pyproject.toml
- Clone this repository, create virtual environment and install packages.
git clone https://github.com/aaronmelton/DownloadRouterConfig.git
cd DownloadRouterConfig
poetry shell
poetry update
- Follow instructions for Python or Docker (below).
python download_router_config.py --help
for help.
Use --device_list <filename>
to specify input file.
Use --backup_to <path>
to specify where to save config files.
For example, python3 download_router_config.py download --device_list switches.txt --backup_to /tmp/
to download the configuration file of all devices mentioned in switches.txt
into the /tmp/
directory.
-
To pull/build the Docker image:
docker build -t download_router_config .
-
To run the script:
docker run -v /local_directory:/container_directory -it -e LOG_LEVEL=DEBUG -e LOG_PATH=/tmp/ --rm download_router_config:latest download --device_list /container_directory/switches.txt --backup_to /container_directory/
Replace the values for LOG_LEVEL, LOG_PATH and CLI arguments (device_list, backup_to) to suit your needs.
- Aaron Melton - Author - Aaron Melton [email protected]