import socket
from contextlib import closing


def check_socket(host: str, port: int) -> bool:
    """Check if given port can be listened to"""

    with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
        sock.settimeout(2)
        try:
            sock.bind((host, port))
            sock.listen(1)
            return True
        except socket.error:
            return False