Guest User

Untitled

a guest
Jan 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # Purpose
  4. # Iterate over a range of IP addresses
  5. # Change the /etc/network/interfaces subnet
  6.  
  7. # WARNING!
  8. # I haven't tested this yet
  9. # It might not work
  10.  
  11. require 'rubygems'
  12. require 'net/ssh'
  13.  
  14. hosts = (2..254).map {|x| "172.16.31.#{x}"}
  15. username = "your_username_here"
  16. password = "your_password_here"
  17. cmd = "sed -i -r -e '/netmask/ s/255.255.255.0/255.255.254.0/' /etc/network/interfaces"
  18.  
  19. hosts.each do |host|
  20. begin
  21. Net::SSH.start( host , username, :password => password, :timeout => 5) do |ssh|
  22. puts ssh.exec! cmd
  23. end
  24. rescue Timeout::Error
  25. puts " Timed out"
  26. puts host
  27. rescue Errno::EHOSTUNREACH
  28. puts " Host unreachable"
  29. puts host
  30. rescue Errno::ECONNREFUSED
  31. puts " Connection refused"
  32. puts host
  33. rescue Net::SSH::AuthenticationFailed
  34. puts " Authentication failure"
  35. puts host
  36. end
  37. end
Add Comment
Please, Sign In to add comment