Created
January 19, 2016 04:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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