#!/bin/bash set -euo pipefail HBBR="hbbr" PID="$(docker inspect -f '{{.State.Pid}}' "$HBBR")" if [ -z "$PID" ] || [ "$PID" = "0" ]; then echo "hbbr container is not running" >&2 exit 1 fi get_connections() { nsenter -t "$PID" -n ss -H -tn state established '( sport = :21117 )' } case "${1:-}" in connections) get_connections | wc -l ;; sessions) count="$(get_connections | wc -l)" echo $((count / 2)) ;; relay_ips) get_connections | awk '{print $4}' | sed -E 's/^\[::ffff:([^]]+)\]:[0-9]+$/\1/' | sort -u ;; *) echo "Usage: $0 {connections|sessions|relay_ips}" >&2 exit 2 ;; esac