MCPcopy Create free account
hub / github.com/Louisym/MiniCC / test_connectivity

Function test_connectivity

tutorials/14b_networking_for_engineers.py:499–508  ·  view source on GitHub ↗

测试能否连接到指定地址

(host, port, timeout=2)

Source from the content-addressed store, hash-verified

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"),

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected