macOS

Figure out IP

I recently needed to get my local IP from the terminal in OSX and I found a crazy way to do that from this StackOverflow question

ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'

It does work even though I don’t really want to spend the brain power needed to understand it enough to explain it.

Finding ports in use

I found this on StackOverflow and depending on your version of macOS, use one of these:

PORT=8000
lsof -n -i4TCP:$PORT | grep LISTEN
lsof -n -iTCP:$PORT | grep LISTEN
lsof -n -i:$PORT | grep LISTEN