MCPcopy Create free account
hub / github.com/InternLM/InternBootcamp / get_external_ip

Function get_external_ip

internbootcamp/utils/tool_server/utils.py:36–51  ·  view source on GitHub ↗

获取外网可访问的IP地址

()

Source from the content-addressed store, hash-verified

34
35
36def get_external_ip() -> str:
37 """获取外网可访问的IP地址"""
38 try:
39 # 优先使用ray获取节点IP
40 if RAY_AVAILABLE:
41 try:
42 return ray.util.get_node_ip_address().strip("[]")
43 except:
44 pass
45
46 # 备用方法:通过连接外部服务器获取本地IP
47 with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
48 sock.connect(("8.8.8.8", 80))
49 return sock.getsockname()[0]
50 except Exception:
51 return "127.0.0.1"
52
53
54def is_port_available(host: str, port: int) -> bool:

Callers 3

start_multiple_workersFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected