check_host_async

async privex.helpers.net.check_host_async(host: Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address], port: Union[decimal.Decimal, int, float, str], version='any', throw=False, **kwargs)bool[source]

AsyncIO version of check_host(). Test if the service on port port for host host is working.

Basic usage (services which send the client data immediately after connecting):

>>> await check_host_async('hiveseed-se.privex.io', 2001)
True
>>> await check_host_async('hiveseed-se.privex.io', 9991)
False

For some services, such as HTTP - it’s necessary to transmit some data to the host before it will send a response. Using the send kwarg, you can transmit an arbitrary string/bytes upon connection.

Sending data to host after connecting:

>>> await check_host_async('files.privex.io', 80, send=b"GET / HTTP/1.1\n\n")
True
Parameters
  • host (str|IPv4Address|IPv6Address) – Hostname or IP to test

  • port (int|str) – Port number on host to connect to

  • version (str|int) – When connecting to a hostname, this can be set to 'v4', 'v6' or similar to ensure the connection is via that IP version

  • throw (bool) – (default: False) When True, will raise exceptions instead of returning False

  • kwargs – Additional configuration options (see below)

  • receive (int) – (default: 100) Amount of bytes to attempt to receive from the server (0 to disable)

  • send (bytes|str) – If send is specified, the data in send will be transmitted to the server before receiving.

  • stype (int) – Socket type, e.g. socket.SOCK_STREAM

  • timeout (float|int) – Socket timeout. If not passed, uses the default from socket.getdefaulttimeout(). If the global default timeout is None, then falls back to 5.0

Raises
Return bool success

True if successfully connected + sent/received data. Otherwise False.