import socket


def has_internet_connection() -> bool:
    """
    test whether a working internet connection is present
    :return: boolean indicating presence of working internet connection
    """

    # test if we could connect to either one of the following websites; it is highly improbable that all of them
    # are down.
    for website in ["www.google.com", "www.amazon.com"]:
        try:
            host = socket.gethostbyname(website)
            s = socket.create_connection((host, 80), 2)
            s.close()
            return True  # connection was established; assuming internet connection is available
        except socket.gaierror:  # could not establish connection with the website
            pass

    return False