1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00

try-connect: check localhost first

This commit is contained in:
2025-12-29 13:32:13 +01:00
parent 6259075f40
commit afb621a98e

View File

@@ -28,6 +28,19 @@ lib.mapAttrs (
writers.writeBashBin "try-connect" '' writers.writeBashBin "try-connect" ''
port=${toString machines.${name}.sshPort} port=${toString machines.${name}.sshPort}
hostname=$(hostname)
if [[ "$hostname" == "${name}" ]]; then
echo "Target is localhost, using ::1 or 127.0.0.1" >&2
if ${netcat}/bin/nc -z -w 2 ::1 "$port" 2>/dev/null; then
echo "::1"
exit 0
fi
if ${netcat}/bin/nc -z -w 2 127.0.0.1 "$port" 2>/dev/null; then
echo "127.0.0.1"
exit 0
fi
fi
for addr in ${lib.concatStringsSep " " addresses.${name}}; do for addr in ${lib.concatStringsSep " " addresses.${name}}; do
# Check if it's an onion address # Check if it's an onion address
if [[ "$addr" == *.onion ]]; then if [[ "$addr" == *.onion ]]; then