# mac changer case ARGV.length when 2 interface = ARGV.shift # first argument is the interface ( usually eth0 ) mac = ARGV.shift # mac address else puts "usage:change.rb " raise SystemExit # we exit the script since we didn't receive proper arguments end if(mac !~ /(?:[0-9a-f][0-9a-f][-:]){5}[0-9a-f][0-9a-f]/i) # check for a valid mac ( or a potentially evil command :) ) puts "#{mac} is an invalid mac" raise SystemExit end case RUBY_PLATFORM when /linux/i # if we're running under linux if(Process.uid != 0) # we should be root puts "script must be ran as root" raise SystemExit end # i didn't want to rely on the presence of which binary , so we search the path for ifconfig's location path = ENV["PATH"] paths = path.split(/:/) ifconf = "" paths.each do |path| Dir.chdir(path) do if(File.exists?("ifconfig")) puts "found ifconfig in #{path}" ifconf = path +"/ifconfig" # if we found ifconfig end end end if(ifconf != "") # if we know ifconfig's location system(ifconf + " #{interface} down"); system(ifconf + " #{interface} hw ether " + mac) system(ifconf + " #{interface} up") puts "changed mac!" else # ifconfig not found , adjust your path puts "ifconfig not found!" raise SystemExit end else puts "#{RUBY_PLATFORM} - unsupported platform!" # not running under linux end