Skip to content

Instantly share code, notes, and snippets.

@simonc
Created October 14, 2009 19:03
Show Gist options
  • Save simonc/210320 to your computer and use it in GitHub Desktop.
Save simonc/210320 to your computer and use it in GitHub Desktop.
Extracts interfaces name and IP address from ifconfig
#!/usr/bin/env ruby
`ifconfig -a`.split(/\n[^\t]/).each do |iface|
name = iface.match(/^(.*?):/)[1]
match = iface.match(/inet ((\d+\.?){4})/)
if match
inet = match[1]
puts "#{name}\t#{inet}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment