Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import sys
- from netaddr import IPAddress
- from netmiko import ConnectHandler
- import netmiko
- import json
- from getpass import getpass
- with open('external.json') as file:
- devices_list = json.load(file)
- file.close()
- netmiko_exceptions = (netmiko.ssh_exception.NetMikoAuthenticationException,
- netmiko.ssh_exception.NetMikoTimeoutException
- )
- admin = input('Type user: ')
- password = getpass(prompt='Password: ')
- for device in devices_list:
- device['username'] = admin
- device['password'] = password
- try:
- connection = ConnectHandler(**device)
- connection.enable()
- if device['device_type'] == 'cisco_nxos':
- hostname = connection.send_command('show hostname')
- licenseid = connection.send_command('show license host-id')
- else:
- hostname = connection.send_command('show run | i host')
- hostname = hostname.replace('hostname ', '')
- licenseid = 'License hostid: no license '
- connection.disconnect()
- except netmiko_exceptions as ex:
- print('Error occur with [{}]'.format(device["ip"]))
- print('The problem touches: {}'.format(ex))
- else:
- # print('else')
- print('Host [{}] {} {}'.format(device['ip'], hostname, licenseid))
- # finally:
- # print('final')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement