Skip to content

Instantly share code, notes, and snippets.

@flores
Forked from lancelakey/interface_change
Created September 22, 2011 01:02
Show Gist options
  • Save flores/1233782 to your computer and use it in GitHub Desktop.
Save flores/1233782 to your computer and use it in GitHub Desktop.
Change /etc/network/interfaces subnet
#!/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