Remove duplication of IP addresses and fix display style

This commit is contained in:
Igor Pecovnik
2025-03-23 19:48:11 +01:00
committed by Igor
parent 1aca28571b
commit 1ee5216a69

View File

@@ -108,6 +108,7 @@ KERNELID=$(uname -r)
ip_address=$(get_ip_addresses &)
wan_ip_address=$(get_wan_address &)
wan_ip6_address=$(get_wan6_address &)
# Get access point info
if systemctl is-active --quiet service hostapd && [[ -f /etc/hostapd/hostapd.conf ]]; then
. /etc/hostapd/hostapd.conf
@@ -185,19 +186,31 @@ fi
# Display IP addresses
IFS='|' read -r ipv4s ipv6s <<< "${ip_address}"
if [[ -n ${ipv4s} ]]; then
all_ip_address=" IPv4 addresses: "
all_ip_address+="\x1B[93m(LAN)\x1B[0m \x1B[92m${ipv4s// /, }\x1B[0m "
# remove WAN IPv4 from the list of all IPv4
if [[ "${ipv4s}" == *${wan_ip_address}* ]]; then
ipv4s=$(echo $ipv4s | sed "s/"${wan_ip_address}"//g" | xargs )
fi
if [[ -n ${ipv4s} || -n ${wan_ip_address} ]]; then
all_ip_address=" IPv4: "
if [[ -n ${ipv4s} ]]; then
all_ip_address+=" \x1B[93m(LAN)\x1B[0m "
fi
all_ip_address+="\x1B[92m${ipv4s// /, }\x1B[0m "
if [[ -n ${wan_ip_address} ]]; then
all_ip_address+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan_ip_address}\x1B[0m "
fi
echo -e "${all_ip_address}"
fi
# remove WAN IPv6 from the list of all IPv6
if [[ -n "${wan_ip6_address}" && "${ipv6s}" == *${wan_ip6_address}* ]]; then
ipv6s=$(echo $ipv6s | sed "s/"${wan_ip6_address}"//g" | xargs )
fi
if [[ -n ${ipv6s} ]]; then
all_ip6_address=" IPv6 addresses: "
all_ip6_address+="\x1B[93m(All)\x1B[0m \x1B[96m${ipv6s// /, }\x1B[0m "
all_ip6_address=" IPv6: "
all_ip6_address+="\x1B[96m${ipv6s// /, }\x1B[0m "
if [[ -n ${wan_ip6_address} ]]; then
all_ip6_address+="\x1B[93m(Outgoing WAN)\x1B[0m \x1B[95m${wan_ip6_address}\x1B[0m "
all_ip6_address+="\x1B[93m(WAN)\x1B[0m \x1B[95m${wan_ip6_address}\x1B[0m "
fi
echo -e "${all_ip6_address}"
fi