Python netmiko library Cisco telnet switch automation

import time
from netmiko import *
import sys
import os
import getpass

# Read the ip address in the iplist.txt file
iplist = open('iplist_cisco.txt', 'r', encoding='ascii')
ip_addr = iplist.readlines()
iplist.close()

cmdlist = open('cmdlist_cisco.txt', 'r', encoding='ascii')
cmd_line = cmdlist.readlines()
cmdlist.close()

# Iterate through the ip_addr list to connect to the ip
for ip in iter(ip_addr):
    print(ip)
    try:
        S5130 = {
            'device_type': 'cisco_ios_telnet',
            'ip': ip,
            'username': 'cisco',
            'password': 'cisco',
        }
        net_connect = ConnectHandler(**S5130)

        for cmd in iter(cmd_line):
            cmd_result = net_connect.send_command(cmd)
            print('-----------------------------------------------------------------')
            print(cmd)
            print(cmd_result)
            print('-----------------------------------------------------------------')
            print('')
        net_connect.disconnect()
    except (EOFError, NetMikoTimeoutException):
        print('Can not connect to Device')
    except (EOFError, NetMikoAuthenticationException):
        print('username/password wrong!')

Read More: