11from __future__ import annotations
22import ipaddress as ip
33import socket
4- import typing as T
4+ import logging
5+ from collections .abc import Iterable
56
67
7- def get_service (b : bytes , service : str | None = None ) -> str :
8+ def get_service (b : bytes , service : str | None = None ) -> str | None :
89 """
910 splitlines is in case the ASCII/UTF8 response is less than 32 bytes,
1011 hoping server sends a \r \n
@@ -20,7 +21,7 @@ def get_service(b: bytes, service: str | None = None) -> str:
2021
2122def is_port_open (
2223 host : ip .IPv4Address , port : int , timeout : float , service : str | None = None
23- ) -> tuple [ip .IPv4Address , str ]:
24+ ) -> tuple [ip .IPv4Address , str ] | None :
2425 """
2526 is a port open? Without coroutines.
2627 """
@@ -38,7 +39,8 @@ def is_port_open(
3839 try :
3940 if not (resp := s .recv (32 )):
4041 return None
41- except (socket .timeout , ConnectionError ):
42+ except (socket .timeout , ConnectionError ) as err :
43+ logging .debug (err )
4244 return None
4345
4446 if svc_txt := get_service (resp , service ):
@@ -49,7 +51,7 @@ def is_port_open(
4951
5052def get_hosts_seq (
5153 net : ip .IPv4Network , port : int , timeout : float , service : str | None = None
52- ) -> T . Iterable [tuple [ip .IPv4Address , str ]]:
54+ ) -> Iterable [tuple [ip .IPv4Address , str ]]:
5355 """
5456 find hosts sequentially (no parallelism or concurrency)
5557 """
0 commit comments