#!/usr/bin/env bash


urls=("https://hiveos.farm/myip/" "https://ifconfig.me/ip/")

get_ip() {
	ip="$(curl -Lks $1)" || return 1
	[[ ! "$ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] && return 2
	echo $ip
	host $ip
}

for url in "${urls[@]}"; do
	get_ip "$url" && break
done
[[ $? -ne 0 ]] && echo "Error detecting IP" >&2 && exit 1

exit 0