Back to Browse

Python learning for Network Engineers | Part 21 |Handle device not reachable exceptions in Netmiko

7.0K views
Apr 7, 2019
15:23

๐—™๐—ผ๐—ฟ ๐—–๐—ผ๐—บ๐—ฝ๐—น๐—ฒ๐˜๐—ฒ ๐—ฃ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—™๐—ผ๐—ฟ ๐—ก๐—ฒ๐˜๐˜„๐—ผ๐—ฟ๐—ธ ๐—˜๐—ป๐—ด๐—ถ๐—ป๐—ฒ๐—ฒ๐—ฟ๐˜€ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ: ๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—ณ๐—ผ๐—ฟ ๐—ฏ๐—ฒ๐—น๐—ผ๐˜„ ๐—จ๐—ฑ๐—ฒ๐—บ๐˜† ๐—–๐—น๐—ฎ๐˜€๐˜€: ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ ๐•๐ž๐ซ๐ฌ๐ข๐จ๐ง ๐‘ซ๐’Š๐’”๐’„๐’๐’–๐’๐’•๐’†๐’… ๐‘น๐’†๐’‡๐’†๐’“๐’“๐’‚๐’ ๐‘ณ๐’Š๐’๐’Œ: https://www.udemy.com/course/python-for-network-engineers/?referralCode=35A75AAE1ACA94A15829 This video demonstrates how to handle Device not reachable, Device unauthorized and SSH not enabled scenariors from netmiko import ConnectHandler from netmiko.ssh_exception import NetMikoTimeoutException from paramiko.ssh_exception import SSHException from netmiko.ssh_exception import AuthenticationException IP_LIST = open('15_devices') for IP in IP_LIST: print ('\n'+ IP.strip() + ' \n' ) RTR = { 'ip': IP, 'username': 'admin', 'password': 'admin1', 'device_type': 'cisco_ios', } try: net_connect = ConnectHandler(**RTR) except NetMikoTimeoutException: print ('Device not reachable.') continue except AuthenticationException: print ('Authentication Failure.') continue except SSHException: print ('Make sure SSH is enabled in device.') continue output = net_connect.send_config_from_file(config_file = '16_config') print(output) output = net_connect.send_command('show ip int brief') print(output) #NetmikoTimeoutExceptions #NetmikoCiscoAuthenticationException #NetmikoSSHException

Download

0 formats

No download links available.

Python learning for Network Engineers | Part 21 |Handle device not reachable exceptions in Netmiko | NatokHD