Skip to content

Instantly share code, notes, and snippets.

@mkelley33
Created June 15, 2012 02:28
Show Gist options
  • Save mkelley33/2934381 to your computer and use it in GitHub Desktop.
Save mkelley33/2934381 to your computer and use it in GitHub Desktop.
Copy computer's IP address to clipboard
# When testing a rails website on my local development machine, I found my
# Parallel's VM wouldn't load 0.0.0.0:3000, 127.0.0.1, or localhost:3000.
#
# So I tried using my computers IP address and voila. I thought I'd hone
# my bash chops a little and extract the IP address with the port number
# concatenated to it. This command puts that on the clipboard so I can just
# paste it into IE so I could browser test.
#
# NOTE: the pbcopy command is Mac specific.
#
# In my .profile:
alias cpip="ifconfig \
| grep en1 -A1 \
| grep -Eo 'inet\ [1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' \
| cut -c 6- \
| xargs -I {} echo {}:'3000' \
| pbcopy"
@mkelley33
Copy link
Author

Thanks for the tips, code, and explanation. Learning more about bash scripting is at the top of my list so this is much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment