Python – Cisco CLI Config Changer

There are three python files.
1. = This is the main file that you run
2. = These are the commands you want to run
3. = These are the devices you want to run the commands on

# Author: Kerry Cordero
# Version: 1.0.0
# Description: This script helps make changes to a Cisco devices via CLI.  It's an easy way to automate simple changes.  This script also dumps the updated configuration to a text file.

import paramiko
import time
import getpass

from network_devices import ip_addresses
from config_file import commands

ID = input("Username : ")
PW = getpass.getpass("Password : ")

# For loop allows you to specify number of hosts
for ip in ip_addresses:
    ssh = paramiko.SSHClient()
    ssh.connect(ip, port=22, username=ID, password=PW)
    remote = ssh.invoke_shell()
    remote.send('term len 0\n')

    # Allows you to specify number of commands you want to enter.  Might need to change sleep timer.
    for command in commands:
        remote.send(' %s \n' % command)
        output = remote.recv(65000)
        logfile = open('configdump-' + ip + '.txt', 'wb')

# Put the commands you want to run.
#commands = ['config t', 'no snmp-server community TEST RO', 'exit', 'wr mem', 'show run']
commands = ['show run']

# List IP Address you want to connect to.  Exp ['', '']
ip_addresses = ['', '']