测试能否连接到指定地址
(host, port, timeout=2)
| 497 | print(" 测试当前网络状态:") |
| 498 | |
| 499 | def test_connectivity(host, port, timeout=2): |
| 500 | """测试能否连接到指定地址""" |
| 501 | try: |
| 502 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 503 | sock.settimeout(timeout) |
| 504 | sock.connect((host, port)) |
| 505 | sock.close() |
| 506 | return True |
| 507 | except (socket.timeout, ConnectionRefusedError, OSError): |
| 508 | return False |
| 509 | |
| 510 | targets = [ |
| 511 | ("127.0.0.1", 22, "本机 SSH"), |
no outgoing calls
no test coverage detected