#!/usr/bin/env bash set -euo pipefail WSL_IP="$(hostname -I | awk '{print $1}')" WSL_HOST_IP="$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf)" WINDOWS_IPS="$( powershell.exe -NoProfile -Command "(Get-NetIPAddress -AddressFamily IPv4 | Where-Object { \$_.IPAddress -notlike '127.*' -and \$_.IPAddress -notlike '169.254*' -and \$_.InterfaceAlias -notlike '*WSL*' } | Select-Object -ExpandProperty IPAddress) -join ','" \ 2>/dev/null | tr -d '\r' )" PORT_REPORT="$(ss -ltnH 2>/dev/null | awk ' { local_addr=$4 n=split(local_addr, parts, ":") if (n < 2) next port=parts[n] host=substr(local_addr, 1, length(local_addr) - length(port) - 1) gsub(/^\[/, "", host) gsub(/\]$/, "", host) key=port SUBSEP host if (!seen[key]++) { hosts[port] = hosts[port] ? hosts[port] "," host : host } } END { for (port in hosts) { print port "|" hosts[port] } } ' | sort -n)" ACTIVE_PORTS="$(printf '%s\n' "$PORT_REPORT" | awk -F'|' ' NF >= 2 { if ($2 !~ /(^|,)(127\.0\.0\.1|::1|localhost)(,|$)/ || $2 ~ /(^|,)(0\.0\.0\.0|\*|::)(,|$)/) { ports = ports ? ports "," $1 : $1 } } END { print ports } ')" LOOPBACK_ONLY_PORTS="$(printf '%s\n' "$PORT_REPORT" | awk -F'|' ' NF >= 2 { if ($2 ~ /(^|,)(127\.0\.0\.1|::1|localhost)(,|$)/ && $2 !~ /(^|,)(0\.0\.0\.0|\*|::)(,|$)/) { ports = ports ? ports "," $1 : $1 } } END { print ports } ')" cat <