Skip to content

Instantly share code, notes, and snippets.

@AJ-Acevedo
Created January 19, 2016 04:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AJ-Acevedo/a4277f1b4b1be009ce51 to your computer and use it in GitHub Desktop.
Save AJ-Acevedo/a4277f1b4b1be009ce51 to your computer and use it in GitHub Desktop.
myIP - Show both the Public and Private IP Addresses on a Mac or Debian Linux system
#!/usr/bin/env bash
#
# myIP
# Description: Show both the Public and Private IP Addresses on a Mac or Debian Linux system.
# Usage: Drop this file in ~/bin, add ~/bin to your $PATH and just type myIP on the CLI. That's it!
#
# URL: AJAlabs.com
# Author: AJ Acevedo
# Copyright (c) 2016 AJ Acevedo
# License: MIT - https://opensource.org/licenses/MIT
#
# Version: v0.2
#
# curl the public IP
publicIP=$(curl -s ifconfig.co)
# Mac OS X Private IP Lookup
if [ `uname -s` == "Darwin" ]; then
privateIP=$(ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2)
fi
# Linux Private IP Lookup (Debian)
if [ `uname -s` == "Linux" ]; then
privateIP=$(hostname -I)
fi
echo -e "\nPrivate IP: $privateIP"
echo -e "Public IP: $publicIP\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment