Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try:
- ssh_session = netmiko.ConnectHandler(device_type='cisco_ios', ip=device_row['device_ip'],
- username=ssh_username, password=ssh_password)
- #global_delay_factor=2)
- #time.sleep(3)
- time.sleep(6)
- ssh_session.clear_buffer()
- print("+++++ {0} +++++".format(device_row['device_ip']))
- commands = ["terminal length 0","terminal width 511","show run | inc hostname","show ip int brief | ex una","show vlan brief","terminal length 70"]
- output = ''
- for cmd in commands:
- output += "n"
- output += ssh_session.send_command(cmd)
- output += "n"
- ssh_session.disconnect()
- with open("pool.txt", 'a') as outputfile:
- for x in output:
- outputfile.write(x)
- except (netmiko.ssh_exception.NetMikoTimeoutException,
- netmiko.ssh_exception.NetMikoAuthenticationException,
- paramiko.ssh_exception.SSHException) as s_error:
- print(s_error)
- show_vlanfile = "pool.txt"
- if os.path.isfile(show_vlanfile):
- try:
- os.remove(show_vlanfile)
- except OSError as e:
- print("Error: %s - %s." %(e.filename, e.strerror))
- parser = ArgumentParser(description='Arguments for running oneLiner.py')
- parser.add_argument('-c', '--csv', required=True, action='store', help='Location of CSV file')
- args = parser.parse_args()
- ssh_username = input("SSH username: ")
- ssh_password = getpass.getpass('SSH Password: ')
- with open(args.csv, "r") as file:
- reader = csv.DictReader(file)
- processes = []
- for device_row in reader:
- processes.append(mp.Process(target=get_info))
Add Comment
Please, Sign In to add comment