Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Purpose
- # Iterate over a range of IP addresses
- # Change the /etc/network/interfaces subnet
- # WARNING!
- # I haven't tested this yet
- # It might not work
- require 'rubygems'
- require 'net/ssh'
- hosts = (2..254).map {|x| "172.16.31.#{x}"}
- username = "your_username_here"
- password = "your_password_here"
- cmd = "sed -i -r -e '/netmask/ s/255.255.255.0/255.255.254.0/' /etc/network/interfaces"
- hosts.each do |host|
- begin
- Net::SSH.start( host , username, :password => password, :timeout => 5) do |ssh|
- puts ssh.exec! cmd
- end
- rescue Timeout::Error
- puts " Timed out"
- puts host
- rescue Errno::EHOSTUNREACH
- puts " Host unreachable"
- puts host
- rescue Errno::ECONNREFUSED
- puts " Connection refused"
- puts host
- rescue Net::SSH::AuthenticationFailed
- puts " Authentication failure"
- puts host
- end
- end
Add Comment
Please, Sign In to add comment