 M test/ensure-web-port.sh
--- diff HEAD ---
diff --git a/test/ensure-web-port.sh b/test/ensure-web-port.sh
index af6bd7ee..19c7103d 100755
--- a/test/ensure-web-port.sh
+++ b/test/ensure-web-port.sh
@@ -2,7 +2,6 @@
 set -euo pipefail
 
 ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
-TEST_PORT=39217
 
 fail() {
   printf 'FAIL: %s\n' "$1" >&2
@@ -22,6 +21,16 @@ if ! python3 -c "import socket; s = socket.socket(socket.AF_INET6, socket.SOCK_S
   exit 0
 fi
 
+TEST_PORT="$(python3 -c "
+import socket
+s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+s.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
+s.bind(('::1', 0))
+port = s.getsockname()[1]
+s.close()
+print(port)
+")"
+
 # IPv6-only listener on ::1 (invisible to IPv4-only probes)
 python3 -c "
 import socket
