Skip to content

Instantly share code, notes, and snippets.

@kfei
Last active December 28, 2015 18:29
Show Gist options
  • Save kfei/7543514 to your computer and use it in GitHub Desktop.
Save kfei/7543514 to your computer and use it in GitHub Desktop.
def get_interface_name
interfaces = {}
puts 'Valid network interfaces detected are:'
interfaces_with_mac = `ifconfig -a | grep -i hwaddr | awk '{ if( match($1, /^eth/) ) {print $1, $5} }'`.lines.map(&:chomp)
interfaces_with_mac.each_with_index do |x, index|
interfaces[index] = x.split[0]
puts " #{index}) #{x.split[0]} ( #{x.split[1]} )"
end
print 'Please choose an interface to configure: '
interface_to_configure = gets.chomp!.to_i
interfaces[interface_to_configure]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment