Created
February 13, 2018 14:21
-
-
Save jezman/bbc3a9214845146356f3c1d856ece363 to your computer and use it in GitHub Desktop.
Fill DHCP table.
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 | |
# Fill DHCP table. | |
require 'optparse' | |
options = {} | |
OptionParser.new do |opt| | |
opt.banner = 'Usage: ruby dhcpfill.rb [options]' | |
opt.on('-i', '--interface NAME', 'Network interface name') { |interface| options[:interface]=interface } | |
opt.on('-m', '--mac XX:XX:XX:XX:XX:XX', 'Mac address. Default - random') { |mac| options[:mac]=mac } | |
opt.on('-h', '--help', 'Displays Help') { puts opt } | |
end.parse! | |
rand_mac = (1..6).map { "%0.2x" % rand(256) }.join(':') | |
interface = options[:interface] if options[:interface] | |
rand_mac = options[:mac] if options[:mac] | |
if options[:interface] | |
if rand_mac =~ /^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/i | |
puts `sudo ifconfig #{interface} down` | |
puts `sudo ifconfig #{interface} up` | |
puts `sudo ifconfig #{interface} hw ether #{rand_mac}` | |
puts("New mac on #{interface}: #{rand_mac}") | |
else | |
puts 'Invalid mac-address' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment