Skip to content

Instantly share code, notes, and snippets.

@mattmacleod
Created November 12, 2014 11:16
Show Gist options
  • Save mattmacleod/534c93845b73301049c7 to your computer and use it in GitHub Desktop.
Save mattmacleod/534c93845b73301049c7 to your computer and use it in GitHub Desktop.
Shell function for showing external and internal IPs
function myip() {
internalip=`ifconfig | ruby -e "print STDIN.readlines.select { |a| a =~ /inet / }.reject { |a| a =~ /127|172/ }.map { |a| a.split(' ')[1] }.join(', ')"`
externalip=`curl -s http://jsonip.com | jq -r .ip | tr -d '\n'`
echo "Internal: $internalip"
echo "External: $externalip"
echo -n $externalip | pbcopy
}
@vorg
Copy link

vorg commented Nov 12, 2014

Installation of jq (json parser) is needed http://stedolan.github.io/jq/

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