This Python script retrieves and saves the running configurations from a list of network switches/routers. It supports multiple vendors and can handle both SSH and Telnet connections. The script uses Netmiko for network device connections and logging for verbose output.
- Automatically detects device types for SSH connections using Netmiko's autodetect feature.
- Supports multiple network device vendors (Cisco, Juniper, Arista, Dell, HP, Huawei, Brocade, Extreme Networks).
- Attempts SSH connection first and falls back to Telnet if SSH fails.
- Logs detailed output to both the console and a log file (
log.txt
). - Saves configurations to individual files named
<ip>_config.txt
in theconfigs
directory.
- Python 3.x
- Netmiko library
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Install the required Python packages:
pip install -r requirements.txt
-i
,--ip
: Single IP address or multiple IP addresses separated by commas.-f
,--file
: File containing a list of IP addresses (one per line).
-
Retrieve configuration from a single IP address:
python script.py --ip 192.168.1.1
-
Retrieve configurations from multiple IP addresses:
python script.py --ip 192.168.1.1,192.168.1.2
-
Retrieve configurations from a file containing IP addresses:
python script.py --file ip_list.txt
-
Run the script with the appropriate arguments:
python script.py --ip 192.168.1.1
-
Input the required credentials when prompted:
- Username
- Password
- Enable Password (if required)
python script.py --ip 192.168.1.1,192.168.1.2
python script.py --file ip_list.txt
The script logs detailed output to both the console and a log.txt
file. The log file includes timestamps, log levels, and messages.
The script supports multiple network device vendors and their respective commands for retrieving running configurations. The COMMANDS
dictionary maps device types to their commands.
COMMANDS = {
'cisco_ios': 'show running-config',
'cisco_nxos': 'show running-config',
'arista_eos': 'show running-config',
'juniper_junos': 'show configuration',
'dell_os10': 'show running-configuration',
'hp_procurve': 'show running-config',
'huawei': 'display current-configuration',
'brocade_fos': 'configshow',
'extreme_exos': 'show config',
}
Feel free to submit issues, fork the repository, and send pull requests. Contributions are welcome!
This project is licensed under the MIT License.