Skip to content

Commit

Permalink
google domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyclenerd committed Apr 14, 2022
1 parent 9ec489e commit a6ee09e
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions myip.sh
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

0 comments on commit a6ee09e

Please sign in to comment.