From fd18995cf36ad14a3ce89dfa0a100bbf629a7529 Mon Sep 17 00:00:00 2001 From: ybyang <10629930+whybeyoung@users.noreply.github.com> Date: Thu, 28 Aug 2025 01:28:52 +0800 Subject: [PATCH] Fix get_ip when no external network (#9700) --- python/sglang/srt/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/sglang/srt/utils.py b/python/sglang/srt/utils.py index 1ef3c8fd6..b5f6626a2 100644 --- a/python/sglang/srt/utils.py +++ b/python/sglang/srt/utils.py @@ -1964,6 +1964,15 @@ def get_ip() -> str: except Exception: pass + # try using hostname + hostname = socket.gethostname() + try: + ip_addr = socket.gethostbyname(hostname) + warnings.warn("using local ip address: {}".format(ip_addr)) + return ip_addr + except Exception: + pass + warnings.warn( "Failed to get the IP address, using 0.0.0.0 by default." "The value can be set by the environment variable"