Guest User

Untitled

a guest
Oct 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. require 'rubygems'
  2. require 'net/ssh/multi'
  3. require 'socket'
  4.  
  5.  
  6. HOSTLIST = ['1.2.3.4','127.0.0.1','128.0.0.1']
  7. USERLIST = ['user','user']
  8. PASSWORD = ['userpegase','userpegase']
  9.  
  10.  
  11. Net::SSH::Multi.start do |session|
  12.  
  13. HOSTLIST.each_with_index do |session_server,index|
  14. begin
  15. session.use session_server , :user => USERLIST[index] , :password => PASSWORD[index], :timeout => 2
  16. session.exec 'pwd' do |ch, stream, data|
  17. puts "[#{ch[session]} : #{stream}] - #{data}"
  18. end
  19. rescue Timeout::Error
  20. puts "+++++++ Timed out"
  21. rescue Net::SSH::ConnectionTimeout
  22. puts "+++++++ Timed out"
  23. rescue Errno::EHOSTUNREACH
  24. puts "+++++++ Host unreachable"
  25. rescue Errno::ECONNREFUSED
  26. puts "+++++++ Connection refused"
  27. rescue Net::SSH::AuthenticationFailed
  28. puts "+++++++ Authentification failure "
  29. rescue SocketError
  30. puts "Got socket error: #"
  31. end
  32. end
  33.  
  34. session.loop
  35.  
  36. end
Add Comment
Please, Sign In to add comment