feat: Always show network info (#1233)

This commit is contained in:
Kroese
2026-07-07 19:37:59 +02:00
committed by GitHub
parent 498248f43e
commit c9a2a6966b
+57 -37
View File
@@ -1309,10 +1309,25 @@ showHostInfo() {
local host=""
local uplink=""
enabled "$DEBUG" || return 0
uplink=$(formatAddress "$UPLINK" "$PREFIX" || true)
[ -z "$uplink" ] && uplink="(none)"
local line=" Host: $uplink"
host=$(containerID)
local line="Host: $host"
[ -n "$host" ] && line+=" ($host)"
local obvious=""
if [[ "$uplink" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)\.[0-9]+$ ]]; then
obvious="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}.1"
fi
local gateway="${GATEWAY:-}"
if [ -z "$gateway" ]; then
line+=" | Gateway: (none)"
elif [[ "$gateway" != "$obvious" ]]; then
line+=" | Gateway: $gateway"
fi
local iface="$DEV"
if [ -n "$NIC" ] && [[ "${NIC,,}" != "veth" ]]; then
@@ -1320,62 +1335,67 @@ showHostInfo() {
fi
[ -z "$iface" ] && iface="(none)"
line+=" Interface: $iface"
uplink=$(formatAddress "$UPLINK" "$PREFIX" || true)
[ -z "$uplink" ] && uplink="(none)"
line+=" IP: $uplink"
local gateway="${GATEWAY:-}"
[ -z "$gateway" ] && gateway="(none)"
line+=" Gateway: $gateway"
[[ "$iface" != "eth0" ]] && line+=" | Interface: $iface"
mtu=$(getMTU "$DEV")
if [ -n "$mtu" ] && [[ "$mtu" != "0" && "$mtu" != "1500" ]]; then
line+=" MTU: $mtu"
line+=" | MTU: $mtu"
fi
local nameservers=""
local file="/etc/resolv.dnsmasq"
[ ! -f "$file" ] && file="/etc/resolv.conf"
if [ -f "$file" ]; then
nameservers=$(grep '^nameserver ' "$file" | sed 's/^nameserver //' | paste -sd ',' | sed 's/,/, /g')
fi
[ -z "$nameservers" ] && nameservers="(none)"
[[ "$nameservers" == "127.0.0.1"* ]] && nameservers=""
echo
if (( ${#nameservers} <= 40 )); then
[ -n "$nameservers" ] && line+=" | DNS: $nameservers"
echo "$line"
else
echo "$line"
echo " DNS: $nameservers"
fi
info "$line"
return 0
}
showGuestInfo() {
local ip="${IP:-}"
local nameservers=""
enabled "$DEBUG" || return 0
local mode="${NETWORK,,}"
isNAT && mode="NAT"
[ -z "$mode" ] && mode="(none)"
local line="Network mode: $mode"
[ -n "$ip" ] && ip=$(formatAddress "$ip" "$PREFIX" || true)
[ -z "$ip" ] && ip="DHCP"
line+=" Guest: $ip"
[ -n "$MAC" ] && line+=" ($MAC)"
local line=" Guest: $ip"
local count="0"
local file="/etc/resolv.dnsmasq"
[ ! -f "$file" ] && file="/etc/resolv.conf"
if [ -f "$file" ]; then
count=$(grep -c '^nameserver ' "$file" || true)
nameservers=$(grep '^nameserver ' "$file" | sed 's/^nameserver //' | paste -sd ',' | sed 's/,/, /g')
if [ -n "${HOST:-}" ]; then
line+=" ($HOST)"
fi
[ -z "$nameservers" ] && nameservers="(none)"
local mode="${NETWORK,,}"
if (( count <= 1 )); then
line+=" Nameserver: $nameservers"
info "$line"
else
info "$line"
info "Nameservers: $nameservers"
if isNAT; then
mode="NAT"
elif enabled "$DHCP"; then
mode="DHCP"
elif isUserMode; then
mode="User ($mode)"
elif [ -z "$mode" ]; then
mode="(none)"
fi
line+=" | Mode: $mode"
[ -n "$MAC" ] && line+=" | MAC: $MAC"
echo "$line"
echo
return 0
}