import socket


def check_host_port(host_ip, port):

    """Check if a connection can be established to the given host and port."""

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    address_str = "Host: {} Port: {} ".format(host_ip, port)

    try:

        s.connect((host_ip, port))
        result = True
        msg = address_str + "OPEN"

    except socket.error:

        result = False
        msg = address_str + "CLOSED"

    finally:

        s.close()

    return result, msg