From 68cb795084086c3a1670e3ca865e5cd4ec1847ef Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 5 Oct 2020 22:07:46 +0000 Subject: [PATCH] fix #142: update for ipify's new API --- myip/myip.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/myip/myip.sh b/myip/myip.sh index aa6980c..1fb90ee 100644 --- a/myip/myip.sh +++ b/myip/myip.sh @@ -1,17 +1,23 @@ #!/bin/bash -{ - set -e +function __show_my_ip { set -u + set -e - ipv4=$(curl -s https://api.ipify.org) - ipv6=$(curl -s https://api6.ipify.org) + ipv4=$(curl -s https://api.ipify.org || true) + ipv6=$(curl -s https://api6.ipify.org || true) - if [ -n "$ipv4" ]; then + if [[ -n "${ipv4}" ]]; then echo "IPv4 (A) : $ipv4" fi - if [ -n "$ipv6" ] && [ "ipv6" != "ipv4" ]; then + if [[ -n "$ipv6" ]] && [[ "ipv6" != "ipv4" ]]; then echo "IPv6 (AAAA): $ipv6" fi + + if [[ -z "$ipv4" ]] && [[ -z "ipv6" ]]; then + >&2 echo "error: no public IP address" + fi } + +__show_my_ip -- 2.25.1