#!/usr/bin/bash

# List of "What is my IP?" type of Web sites to test
#
MyIpSites=("ifconfig.me/ip 
            v4.ident.me 
            api.ipify.org 
            ipinfo.io/ip
            ipecho.net/plain
            icanhazip.com
            ipgrab.io
            ip4only.me/api/
            ipv4-a.jsonip.com
            freedns.afraid.org/dynamic/check.php
            checkip.dyndns.org")

# Select curl or wget to perform the query
#
cmd="curl --connect-timeout 1 --max-redir 0 --retry 2 -s"
#cmd="wget --timeout=1 --max-redirect=0 --tries=3 -q -O-"

#----- no need to modify below ----------------------------

chosen=${cmd%% *} # extract the first word of $cmd 


echo "Testing \"what is my IP?\" type Web sites with $chosen."
echo "Be patient, some sites may not be on line or accept a protocol."

for site in $MyIpSites; do
  echo -e "\n$site:"
    url="http://$site"
    res=`$cmd "$url"`
    echo "    http:=>$res<="
    
    url="https://$site"
    res=`$cmd "$url"`
    echo "   https:=>$res<="
done

# Note: checkip.dyndns.org appends a trailing carriage return which
# explains why the closing "<=" is displayed over the two spaces at
# the start of the line.
