Skip to content

Instantly share code, notes, and snippets.

@rafbm
Created April 15, 2012 02:17
Show Gist options
  • Save rafbm/2389381 to your computer and use it in GitHub Desktop.
Save rafbm/2389381 to your computer and use it in GitHub Desktop.
Copy your local IP address from the command line (OS X)
# I often need this IP for testing local websites in VirtualBox
echo -n `ifconfig | grep -Po "(?<=inet )\d*\.\d*\.\d*\.\d*(?=.*broadcast)"` | pbcopy
# Less Unix-y, somewhat more readable version
ifconfig | ruby -e "print STDIN.read.match(/inet (\d*\.\d*\.\d*\.\d*).*broadcast/)[1]" | pbcopy
# I use it like this in my .zshrc
alias ip='echo -n `ifconfig | grep -Po "(?<=inet )\d*\.\d*\.\d*\.\d*(?=.*broadcast)"` | pbcopy'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment