-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
16 additions
and
27 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
# exit_with_failure() outputs and a message before exiting the script. | ||
function exit_with_failure() { | ||
echo | ||
echo "$1" | ||
echo | ||
exit 9 | ||
} | ||
|
||
# command_exists() tells if a given command exists. | ||
function command_exists() { | ||
command -v "$1" >/dev/null 2>&1 | ||
} | ||
|
||
if ! command_exists curl; then | ||
exit_with_failure "'curl' is needed. Please install 'curl'. More details can be found at https://curl.haxx.se/" | ||
fi | ||
# | ||
# Get public external IPv4 address of your own local network | ||
# | ||
|
||
ip=$(curl -s https://api.ipify.org) | ||
# External URL that returns your IP | ||
MY_GET_IP_URL="https://domains.google.com/checkip" | ||
#MY_GET_IP_URL="https://ifconfig.me" | ||
#MY_GET_IP_URL="http://whatismyip.akamai.com/" | ||
#MY_GET_IP_URL="https://api.ipify.org" | ||
|
||
echo | ||
echo -n "Public IP Address: $ip" | ||
command -v curl >/dev/null 2>&1 || { echo >&2 "'curl' is needed. Please install 'curl'. More details can be found at https://curl.haxx.se/"; exit 1; } | ||
|
||
# Onyl macOS | ||
if command_exists pbcopy; then | ||
echo "$ip" | pbcopy | ||
echo -n " (copied to clipboard)" | ||
fi | ||
|
||
echo | ||
echo | ||
MY_EXTERNAL_IP=$(curl -4 --silent "$MY_GET_IP_URL") | ||
if [ -z "$MY_EXTERNAL_IP" ]; then | ||
echo "!!! ERROR !!! Could not discover current external IPv4 address" | ||
exit 9 | ||
else | ||
echo "$MY_EXTERNAL_IP" | ||
fi |