(host: str, port: int)
| 188 | |
| 189 | |
| 190 | def port_is_available(host: str, port: int) -> bool: |
| 191 | probe_host = host or "0.0.0.0" |
| 192 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: |
| 193 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 194 | try: |
| 195 | sock.bind((probe_host, port)) |
| 196 | return True |
| 197 | except OSError: |
| 198 | return False |
| 199 | |
| 200 | |
| 201 | def resolve_available_port(host: str, preferred_port: int, max_scan: int = 100) -> int: |
no outgoing calls
no test coverage detected