#!/usr/bin/python3
# coding: utf-8

# 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']
 
#----- no need to modify below ----------------------------
 
from requests import get

headers = {'Pragma': 'no-cache', 'Cache-Control' : 'no-cache' } 

def getIP(proto, site):
   #print('{}://{}'.format(proto, site))
   try:
     hf = get('{}://{}'.format(proto, site), headers, timeout=1, allow_redirects=False)   
     print('    {} =>{}<='.format(proto, hf.text))
   except:
     print('    {} =>Error<='.format(proto))


print("Testing \"what is my IP?\" type Web sites with request.get.")
print("Be patient, some sites may not be on line or accept a protocol.")

for site in MyIpSites:
  print('\n{}:'.format(site))	
  getIP('http', site)
  getIP('https',site)
