-
pxblat.check_port_in_use(host: str, port: int, tries: int =
3) bool[source] Check if a given port on a host is in use.
- Parameters:¶
- Returns:¶
True if the port is in use, False otherwise.
- Return type:¶
- Raises:¶
TypeError – If the host argument is not a string.
ValueError – If the port argument is not a valid port number.
This function attempts to connect to the specified host and port using the socket library. It will attempt the connection a number of times specified by the tries argument. If the connection is successful, it will return True, indicating that the port is in use. If the connection fails, it will return False.
If the host argument is not a string, a TypeError will be raised. If the port argument is not a valid port number, a ValueError will be raised.
Example
>>> check_port_in_use("localhost", 8080) True