Files
proxmox/scripts/check-network-rpc-138.sh

66 lines
1.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Check network connectivity to Chain 138 RPC endpoints.
# Usage: ./scripts/check-network-rpc-138.sh [RPC_HOST] [PORT]
# Default: 192.168.11.211 8545 (Core RPC — VMID 2101)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
source "${PROJECT_ROOT}/config/ip-addresses.conf" 2>/dev/null || true
HOST="${1:-${RPC_CORE_1:-192.168.11.211}}"
PORT="${2:-8545}"
RPC_URL="http://${HOST}:${PORT}"
echo "=== Network connection check: $HOST (port $PORT) ==="
echo ""
# 1. Route
echo "--- Route ---"
if command -v ip &>/dev/null; then
ip route get "$HOST" 2>/dev/null || echo "No route to $HOST"
else
route -n 2>/dev/null | head -5
fi
echo ""
# 2. Ping (L3)
echo "--- Ping (L3) ---"
if ping -c 2 -W 2 "$HOST" 2>&1; then
echo "Ping: OK"
else
echo "Ping: FAIL (host or ICMP unreachable)"
fi
echo ""
# 3. TCP port (L4)
echo "--- TCP port $PORT (L4) ---"
if command -v nc &>/dev/null; then
if nc -zv -w 3 "$HOST" "$PORT" 2>&1; then
echo "Port $PORT: OPEN"
else
echo "Port $PORT: REFUSED or FILTERED (nothing listening or firewall)"
fi
else
echo "nc not found; trying curl..."
curl -s -m 3 -o /dev/null -w "curl exit %{errno}: %{errno}\n" "$RPC_URL" 2>&1 || true
fi
echo ""
# 4. JSON-RPC (application)
echo "--- JSON-RPC eth_chainId ---"
resp=$(curl -s -m 5 -X POST "$RPC_URL" -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}' 2>&1) || true
if echo "$resp" | grep -q '"result"'; then
echo "RPC: OK — $resp"
else
echo "RPC: FAIL — ${resp:-empty or connection failed}"
fi
echo ""
echo "Summary:"
echo " - Ping OK + Port REFUSED = host up, service not listening (start Besu RPC in container)."
echo " - Ping OK + Port OPEN + RPC FAIL = service up but not responding JSON-RPC."
echo " - Ping FAIL = host down or network/firewall blocking ICMP."