检查端口是否可用
(host: str, port: int)
| 52 | |
| 53 | |
| 54 | def is_port_available(host: str, port: int) -> bool: |
| 55 | """检查端口是否可用""" |
| 56 | try: |
| 57 | with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: |
| 58 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 59 | return sock.connect_ex((host, port)) != 0 |
| 60 | except Exception as e: |
| 61 | traceback.print_exc() |
| 62 | return False |
| 63 | |
| 64 | |
| 65 | def find_available_port(host: str, start_port: int, max_port: int = 65535, |
no outgoing calls
no test coverage detected