import socket


def have_connectivity(host="8.8.8.8", port=53, timeout=3):
    """ Attempt to make a DNS connection to see if we're on the Internet.
    From https://stackoverflow.com/questions/3764291/checking-network-connection
    @param host: the host IP to connect to (default 8.8.8.8, google-public-dns-a.google.com)
    @param port: the port to connect to (default 53, TCP)
    @param timeout: seconds before timeout (default 3)
    @returns: True if connected; False otherwise.
    """
    try:
        socket.setdefaulttimeout(timeout)
        socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
        return True
    except Exception as ex:
        return False