备份
>>> from socket import socket >>> def scan_address(host, port): s = socket() s.settimeout(3) try: s.connect((host, port)) except: return False s.close() return True >>> scan_address('localhost', 5432) True