XX-net/XX-Net · warning
get local ip fail:%r
Error message
get local ip fail:%r
What it means
On Windows, get_local_ips() tries socket.gethostbyname_ex(socket.gethostname()) to enumerate local IPv4 addresses; on failure (DNS/hostname resolution error, Unicode hostname, no IPv4) it logs this warning and falls back to [b'127.0.0.1'].
Source
Thrown at code/default/smart_router/local/dns_query.py:82
elif sys.platform == "darwin":
try:
proc = subprocess.Popen(["ifconfig | egrep inet | awk '{{print $2}}' | awk -F'/' '{{print $1}}'"],
stdout=subprocess.PIPE, shell=True)
x = proc.communicate()[0]
ips = x.strip().split(b"\n")
except Exception as e:
xlog.warn("get ip address e:%r", e)
ips = [b'127.0.0.1']
elif sys.platform == "ios":
ips = [b'127.0.0.1']
elif sys.platform == "win32":
try:
ips = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]]
ips = utils.to_bytes(ips)
if b"127.0.0.1" not in ips:
ips.append(b"127.0.0.1")
except Exception as e:
xlog.warn("get local ip fail:%r", e)
ips = [b"127.0.0.1"]
else:
ips = []
try:
for ix in socket.if_nameindex():
name = ix[1]
ip = get_ip_address(name)
ips.append(ip)
except Exception as e:
xlog.warn("get ip address e:%r", e)
ips = [b'127.0.0.1']
xlog.debug("local ips: %s", ips)
return ips
def query_dns_from_xxnet(domain, dns_type=None):
if not g.x_tunnel:View on GitHub (pinned to cfa5bc17b6)
Solutions
- Verify the hostname resolves: 'ping %COMPUTERNAME%' should return a local IP; if not, add an entry to C:\Windows\System32\drivers\etc\hosts mapping the hostname to 127.0.0.1.
- Rename the machine to an ASCII hostname if it contains non-ASCII characters.
- Use a more robust enumeration (e.g. iterating if_nameindex/get_ip_address or calling GetAdaptersAddresses) instead of gethostbyname_ex.
- Accept the 127.0.0.1 fallback if only loopback detection matters.
Example fix
// before
ips = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]]
// after
try:
ips = [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2]]
except socket.gaierror:
ips = []
for ix in socket.if_nameindex():
ip = get_ip_address(ix[1])
if ip and ip not in ips:
ips.append(ip) Defensive patterns
Strategy: fallback
Validate before calling
import socket
try:
socket.gethostbyname_ex(socket.gethostname())
except socket.gaierror:
print('hostname unresolvable; local IP detection will use 127.0.0.1 only') Try / catch
try:
ips = get_local_ips()
except Exception:
ips = [b'127.0.0.1'] Prevention
- Add the machine hostname to the hosts file on Windows to make gethostbyname_ex succeed.
- Keep hostnames ASCII-only.
- Treat g.local_ips as possibly loopback-only and don't gate critical logic on real IPs being present.
When it happens
Trigger: Calling smart router start() on win32 where gethostbyname_ex raises socket.gaierror or herror — e.g. hostname not resolvable via hosts file/DNS, machine renamed, or hostname containing non-ASCII characters.
Common situations: Fresh Windows installs where the hostname isn't in the hosts file; corporate DNS refusing local hostname resolution; hostnames with non-ASCII characters breaking gethostbyname_ex; machines with no active IPv4 interface.
Related errors
AI-assisted analysis of XX-net/XX-Net@cfa5bc17b6 (2026-08-27).
Data as JSON: /api/errors/ccc3895f5ce1a13c.
Report an issue: GitHub.