Created
October 14, 2009 19:03
-
-
Save simonc/210320 to your computer and use it in GitHub Desktop.
Extracts interfaces name and IP address from ifconfig
This file contains 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 | |
`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