import socket


def has_internet(host='8.8.8.8', port=53, timeout=20):
    """
    Check if there is internet connection.

    Parameters
    ----------
    host : str, default '8.8.8.8'
        IP to ping. the default is google DNS server.
    port : int, default 53
        the port to ping the server on.
    timeout : int, default 20
        the timeout window for pinging.

    Returns
    -------
    bool
        if there is internet connection True, otherwise False.
    """
    try:
        socket.setdefaulttimeout(timeout)
        socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
        return True
    except Exception:
        return False