XX-net/XX-Net · warning

get ip address e:%r

Error message

get ip address e:%r

What it means

On Linux, get_local_ips() shells out to 'ip addr show | egrep inet | awk ...' to enumerate local interface addresses; any failure (missing ip/awk binaries, shell error, encoding issue) is caught, logged with this warning, and the function degrades to returning [b'127.0.0.1']. Functional but reduces smart_router accuracy.

Source

Thrown at code/default/smart_router/local/dns_query.py:62

        return socket.inet_ntoa(fcntl.ioctl(
            s.fileno(),
            0x8915,  # SIOCGIFADDR
            struct.pack('256s', NICname[:15].encode("UTF-8"))
        )[20:24])

    if sys.platform.startswith("linux"):

        if os.path.isfile("/system/bin/dalvikvm") or os.path.isfile("/system/bin/dalvikvm64") or \
                "android.googlesource.com" in sys.version:
            ips = [b'127.0.0.1']
        else:
            try:
                proc = subprocess.Popen(["ip addr show | 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 == "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")

View on GitHub (pinned to cfa5bc17b6)

Solutions

  1. Install iproute2 and gawk (or verify 'ip addr show' runs in the same environment the launcher uses).
  2. Prefer a pure-Python fallback using socket.if_nameindex()/get_ip_address (the branch already used for other platforms) instead of shelling out.
  3. Check PATH when running under systemd/supervisor; use absolute paths like /sbin/ip.
  4. Ignore the warning if loopback-only detection is acceptable for your deployment.

Example fix

// before
proc = subprocess.Popen(["ip addr show | egrep inet | awk '{{print $2}}' | awk -F'/' '{{print $1}}'"], stdout=subprocess.PIPE, shell=True)

// after
ips = []
for ix in socket.if_nameindex():
    ip = get_ip_address(ix[1])
    if ip:
        ips.append(ip)
Defensive patterns

Strategy: fallback

Validate before calling

import shutil
if not shutil.which('ip'):
    # pre-check before triggering smart router start
    print('iproute2 missing; local IP detection will fall back to 127.0.0.1')

Try / catch

try:
    ips = get_local_ips()
except Exception:
    ips = [b'127.0.0.1']  # function already self-falls-back; guard callers against empty lists

Prevention

When it happens

Trigger: Calling start() on the smart router (which calls get_local_ips) on a minimal Linux system without iproute2 or awk, or where /sbin is not on PATH for the subprocess, or where subprocess/shell invocation raises OSError.

Common situations: Docker/alpine/minimal containers lacking iproute2; hardened environments restricting shell=True subprocesses; PATH differences when launched from a service manager; busybox systems with different output formatting.

Related errors


AI-assisted analysis of XX-net/XX-Net@cfa5bc17b6 (2026-08-27). Data as JSON: /api/errors/9b060e02fd100ac0. Report an issue: GitHub.