-
-
Save flores/1233782 to your computer and use it in GitHub Desktop.
Change /etc/network/interfaces subnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 && echo $?" | |
hosts.each do |host| | |
begin | |
Net::SSH.start( host , username, :password => password, :timeout => 5) do |ssh| | |
results = ssh.exec! cmd | |
if results = 0 | |
puts "everything went well!" | |
else | |
puts "error status #{results}" | |
end | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment