Skip to content

Instantly share code, notes, and snippets.

@jdlich
Created July 22, 2011 00:25
Show Gist options
  • Save jdlich/1098564 to your computer and use it in GitHub Desktop.
Save jdlich/1098564 to your computer and use it in GitHub Desktop.
ruby one-liner to grab ip address
# os x (copies ip to clipboard)
ifconfig en1 | ruby -ne '$_.match(/inet\s((\d|\.)+)/) { print $1 }' | pbcopy
# ubuntu
# make sure you have xclip: apt-get install xclip
# (also make sure to paste with the middle mouse button...)
ifconfig eth0 | ruby -ne '$_.match(/inet\saddr:((\d|\.)+)/) { print $1 }' | xclip
# wrap it with a function in .bashrc (don't forget the semi-colon)
function ip { COMMAND; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment