Portability: python/python3 note + cross-shell lab commands (#31,#32) (#62)
Co-authored-by: claude <claude@jpaul.io> Co-committed-by: claude <claude@jpaul.io>
This commit was merged in pull request #62.
This commit is contained in:
@@ -15,6 +15,26 @@ set -u
|
||||
|
||||
line() { printf '\n=== %s ===\n' "$1"; }
|
||||
|
||||
# Try a TCP connect to host:port with a ~2s deadline, portably.
|
||||
# GNU `timeout` (Linux) or Homebrew's `gtimeout` are used when present; otherwise a bash-native
|
||||
# background-and-kill fallback keeps this working on stock macOS, which ships no GNU `timeout`.
|
||||
tcp_probe() {
|
||||
host="$1"; port="$2"
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
timeout 2 bash -c ">/dev/tcp/${host}/${port}" 2>/dev/null
|
||||
elif command -v gtimeout >/dev/null 2>&1; then
|
||||
gtimeout 2 bash -c ">/dev/tcp/${host}/${port}" 2>/dev/null
|
||||
else
|
||||
bash -c ">/dev/tcp/${host}/${port}" 2>/dev/null &
|
||||
probe_pid=$!
|
||||
( sleep 2; kill "$probe_pid" 2>/dev/null ) >/dev/null 2>&1 &
|
||||
killer_pid=$!
|
||||
rc=0; wait "$probe_pid" 2>/dev/null || rc=$?
|
||||
kill "$killer_pid" 2>/dev/null
|
||||
return "$rc"
|
||||
fi
|
||||
}
|
||||
|
||||
line "WHO AND WHERE"
|
||||
echo "hostname : $(hostname 2>/dev/null)"
|
||||
echo "user : $(whoami 2>/dev/null) (root? $( [ "$(id -u 2>/dev/null)" = 0 ] && echo YES || echo no ))"
|
||||
@@ -62,7 +82,7 @@ line "PRIVATE NETWORK REACH (the reason you self-host — and the reason it's da
|
||||
PROBES=( "192.168.0.1:80" "192.168.1.1:80" "10.0.0.1:80" )
|
||||
for hp in "${PROBES[@]}"; do
|
||||
host="${hp%%:*}"; port="${hp##*:}"
|
||||
if timeout 2 bash -c ">/dev/tcp/${host}/${port}" 2>/dev/null; then
|
||||
if tcp_probe "$host" "$port"; then
|
||||
echo " REACHABLE: ${host}:${port}"
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user