Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import paramiko
  2. paramiko.util.log_to_file("paramiko.log")
  3.  
  4. error_log = file('error_log.txt', 'w')
  5. access_log = file('access_log.txt', 'w')
  6.  
  7. timeout = 10.0
  8. banner_timeout = 10.0
  9.  
  10. for sw in file('sw.txt').readlines():
  11. codigo, nome, ip, modelo = sw.strip('\n').split()
  12. print "Testando %s ..." % nome
  13.  
  14. try:
  15. client = paramiko.SSHClient()
  16. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  17. client.connect(ip, username='XXXXX', password='XXXXX', allow_agent=False, look_for_keys=False, timeout=timeout, banner_timeout=banner_timeout)
  18. client.invoke_shell()
  19. client.close()
  20. access_log.write("%s %s %s %s\n" % (codigo, nome, ip, modelo))
  21. print 'Sucesso!'
  22. except Exception, e:
  23. error_log.write("%s %s %s %s -- EXCEPTION: %s -- ERRO: %s\n" % (codigo, nome, ip, modelo, e.__class__, e.message))
  24. print 'Falhou'
  25.  
  26. error_log.close()
  27. access_log.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement