Posts

Showing posts from May, 2024

Multiple Cisco device configuration Backup using python Script

Image
 Multiple Cisco device configuration Backup using python Script Device configuration will be saved as per Hostname.    Saved files are looking as below:  ===================  Python Script: ===================  from netmiko import ConnectHandler import pandas as pd import datetime import os # Read device information from the Excel file device_file = "devices.xlsx" devices_df = pd.read_excel(device_file) # Convert the dataframe to a list of dictionaries devices = devices_df.to_dict( orient = 'records' ) # Directory to save the configuration files output_directory = "device_configs" os.makedirs(output_directory, exist_ok = True ) # Define the commands to be executed commands = [ 'show running-config' , 'show ip interface brief' , 'show version' ] # Get the current date current_date = datetime.datetime.now().strftime( "%Y-%m-%d" ) # Function to connect to a device and save the output to a file def connect_and_save (

Multiple Cisco device Backup Python Script using Telnet with different port

Image
 Multiple device Backup Python Script using Telnet with different port File will be saved using Device IP address   Need to create a xl file the same file location as named device Create an Excel file (e.g., devices.xlsx )  from netmiko import ConnectHandler import pandas as pd import datetime import os # Read device information from the Excel file device_file = "devices.xlsx" devices_df = pd.read_excel(device_file) # Convert the dataframe to a list of dictionaries devices = devices_df.to_dict( orient = 'records' ) # Directory to save the configuration files output_directory = "device_configs" os.makedirs(output_directory, exist_ok = True ) # Define the commands to be executed commands = [ 'show running-config' , 'show version' ] # Get the current date current_date = datetime.datetime.now().strftime( "%Y-%m-%d" ) # Function to connect to a device and save the output to a file def connect_and_save ( device ): try :

Telnet with different port a cisco device login and show command using python script

 Telnet with different port a Cisco device login and show command using python script from netmiko import ConnectHandler # Device information device = { 'device_type' : 'cisco_ios_telnet' , # Specify Telnet connection 'host' : '192.168.1.1' , # IP address of the Cisco device 'port' : '32914' , 'username' : 'cisco' , # Telnet username 'password' : 'cisco' , # Telnet password 'secret' : 'cisco' , # Enable password (if needed) } try : # Establish Telnet connection net_connect = ConnectHandler(**device) # Enter enable mode net_connect.enable() # Define the commands to be executed      commands = [      'show run' ,      'show ip interface brief' ,      'show version' ,      ] # Execute each command and capture the output for command in commands: output = net_connect.send_command(command)