#!/bin/sh
# Print this host's public IP address, as seen from the internet.
# https only, fail on HTTP errors, bounded time, and the answer has to look
# like an address before it is printed: this can end up in a status bar.

ip=""
for url in https://checkip.amazonaws.com https://ipinfo.io/ip https://api.ipify.org; do
	ip=$(curl -fsS --max-time 5 "$url" 2>/dev/null | tr -d '[:space:]')
	case "$ip" in
		"") continue ;;
		*[!0-9a-fA-F.:]*) ip=""; continue ;;
	esac
	break
done
[ -n "$ip" ] || exit 1
printf '%s\n' "$ip"
