Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. #! /usr/bin/env python3
  2. #_*_coding: utf8_*_
  3. #__author__ = 'Taxxer'
  4.  
  5. import paramiko, time, datetime, os
  6.  
  7.  
  8. login = 'adminX'
  9. passw = 'adminX0'
  10. port = 22
  11. comm = 'put [system resource get uptime ]'
  12. file = open('host.txt')
  13. need = file.read().rstrip().split('\n')
  14. times=datetime.datetime.now()
  15. ccount=0
  16. ecount=0
  17. print("Hello, I'm ssh paramiko\n if you load ip addresses in file\n let's begin")
  18. print('')
  19. #print('Enter login:')
  20. #login=str(input())
  21. #print('Enter Password:')
  22. #passw=str(input())
  23. #print('Enter Port:')
  24. #port=int(input())
  25. #print('Enter Command:')
  26. #comm=str(input())
  27.  
  28.  
  29. try:
  30.     y = os.mkdir('C:\\Users\\lixdv.ISKRA\\PycharmProjects\\untitled\\New_Work\zx\\%s\\' % times.strftime("%d-%m-%Y %I_%M%p"))
  31. except:
  32.     print('Папка с файлами уже существует %s, удалите.' % times.strftime("%d-%m-%Y %I_%M%p"))
  33.     print('Завершаю выполнение просцесса.')
  34.     quit()
  35. else:
  36.     x = ('C:\\Users\\lixdv.ISKRA\\PycharmProjects\\untitled\\New_Work\zx\\%s\\' % times.strftime("%d-%m-%Y %I_%M%p"))
  37.  
  38. ip=[]
  39. for i in need:
  40.     print(i+'*'*10)
  41.     ip.append(i)
  42.  
  43.     try:
  44.         client = paramiko.SSHClient()
  45.         client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  46.         client.connect(hostname=i, username=login, password=passw, port=port, timeout=2)
  47.         print('connect', )
  48.         ccount+=1
  49.     except:
  50.         print('except')
  51.         with open(x+'\errors.txt', 'a') as f:
  52.             read = f.write(i+'\n')
  53.             ecount+=1
  54.     else:
  55.         stdin, stdout, stderr = client.exec_command(comm)
  56.         print('else')
  57.         data = stdout.read().decode('utf-8') + stderr.read().decode('utf-8')
  58.         with open(x+i+'.txt', 'w') as f:
  59.             read = f.write(data)
  60. with open(x + '\command.txt', 'a') as f:
  61.     read = f.write(comm)
  62.  
  63. print("I'm Done!")
  64. print('')
  65. print('Успешных подключений: '+str(ccount))
  66. print('Внесено в errors: '+str(ecount))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement