aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-11-06 09:16:34 +0800
committerAaron LI <aly@aaronly.me>2017-11-06 09:16:34 +0800
commitefbe09205ca012151e40cf3b7690cc57476a1258 (patch)
treebd921955eac2c05d9b59adf5e4c4e66bd75f3f38
parentc5ba47499baa00c11f0f51e71720b24ac1ffc6d3 (diff)
downloadatoolbox-efbe09205ca012151e40cf3b7690cc57476a1258.tar.bz2
get-ip.sh: Use icanhazip.com and support IPv6 also
-rwxr-xr-xcli/get-ip.sh17
1 files changed, 12 insertions, 5 deletions
diff --git a/cli/get-ip.sh b/cli/get-ip.sh
index 3bfc660..27da1cb 100755
--- a/cli/get-ip.sh
+++ b/cli/get-ip.sh
@@ -1,8 +1,12 @@
#!/bin/sh
#
-# Get the public IPv4 address.
+# Get the public IPv4 & IPv6 address.
#
# Credit:
+# * icanhaz:
+# - https://icanhazip.com
+# - https://major.io/icanhazip-com-faq/
+# - https://github.com/major/icanhaz
# * http://ifconfig.me/
# * http://ipecho.net/
#
@@ -11,8 +15,11 @@
# MIT license
#
-URL="http://ifconfig.me"
-URL="http://ipecho.net/plain"
+#URL="http://ifconfig.me" # IPv4 only
+#URL="http://ipecho.net/plain" # IPv4 only
+URL="https://icanhazip.com" # IPv4 & IPv6
-ip=$(curl -s ${URL})
-echo ${ip}
+ipv4=$(curl -4s ${URL} 2>/dev/null)
+ipv6=$(curl -6s ${URL} 2>/dev/null)
+[ -n "${ipv4}" ] && echo "IPv4: ${ipv4}"
+[ -n "${ipv6}" ] && echo "IPv6: ${ipv6}"