SHARE
TWEET

Untitled

a guest Dec 31st, 2018 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import threading
  2.  
  3. import netmiko
  4. import getpass
  5.  
  6. # global variables
  7. _platform = 'cisco_ios'
  8. _username = raw_input("Username?:")
  9. _password = getpass.getpass(prompt="Password?:")
  10. _port = 4000
  11. _data = open("hosts.txt")
  12.  
  13.  
  14. def send_command(command, ip):
  15.     try:
  16.         dev_ssh = netmiko.ConnectHandler(
  17.             device_type=platform,
  18.             ip=ip,
  19.             username=_username,
  20.             password=_password,
  21.             port=_port,
  22.             secret=_password,
  23.             )
  24.         output = dev_ssh.send_command_timing(command).split()
  25.         if 'Version' in output:
  26.             output = dev_ssh.send_command_timing('\r\n').split()
  27.  
  28.         with open(ip + '_wrmem.txt','w+') as file:
  29.             for line in output:
  30.                 file.write(line)
  31.  
  32.         print('{} -- Complete'.format(ip))
  33.  
  34.     except:
  35.         continue
  36.  
  37.  
  38. def main():
  39.     all_devices = [ip for ip in _data]
  40.     thread_list = [threading.Thread(target=send_command, args=('wr mem',ip,)) for ip in all_devices]
  41.  
  42.     for thread in thread_list:
  43.         thread.start()
  44.     for thread in thread_list:
  45.         thread.join()
  46.  
  47. if __name__ == '__main__':
  48.     main()
  49.     print('Complete')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top