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 portportfor hosthostis 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
sendkwarg, you can transmit an arbitrary string/bytes upon connection.Sending data to
hostafter 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
hostto connect toversion (str|int) – When connecting to a hostname, this can be set to
'v4','v6'or similar to ensure the connection is via that IP versionthrow (bool) – (default:
False) WhenTrue, will raise exceptions instead of returningFalsekwargs – Additional configuration options (see below)
receive (int) – (default:
100) Amount of bytes to attempt to receive from the server (0to disable)send (bytes|str) – If
sendis specified, the data insendwill be transmitted to the server before receiving.stype (int) – Socket type, e.g.
socket.SOCK_STREAMtimeout (float|int) – Socket timeout. If not passed, uses the default from
socket.getdefaulttimeout(). If the global default timeout isNone, then falls back to5.0
- Raises
socket.timeout – When
throw=Trueand a timeout occurs.socket.gaierror – When
throw=Trueand various errors occurConnectionRefusedError – When
throw=Trueand the connection was refusedConnectionResetError – When
throw=Trueand the connection was reset
- Return bool success
Trueif successfully connected + sent/received data. OtherwiseFalse.