diff --git a/peer-count.sh b/peer-count.sh index 674e8425..f5a12fa7 100755 --- a/peer-count.sh +++ b/peer-count.sh @@ -27,16 +27,35 @@ for path in $pathlist; do if $include; then RPC_URL="${PROTO:-https}://$DOMAIN/$path" + # First, get the running client's own version using admin_nodeInfo + node_info_response=$(curl --ipv4 -L -s -X POST "$RPC_URL" \ + -H "Content-Type: application/json" \ + --data '{"jsonrpc":"2.0","method":"admin_nodeInfo","params":[],"id":1}' 2>/dev/null) + + running_client_version="" + if echo "$node_info_response" | jq -e '.result.name' > /dev/null 2>&1; then + running_client_full_name=$(echo "$node_info_response" | jq -r '.result.name // empty' 2>/dev/null) + if [ -n "$running_client_full_name" ]; then + # Extract client/version from name (e.g., "Geth/v1.13.0-stable/..." -> "Geth/v1.13.0-stable") + running_client_version=$(echo "$running_client_full_name" | sed -E 's|^([^/]+)/([^/]+).*|\1/\2|') + fi + fi + # Try admin_peers first (returns detailed peer info) response=$(curl --ipv4 -L -s -X POST "$RPC_URL" \ -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"admin_peers","params":[],"id":1}') + --data '{"jsonrpc":"2.0","method":"admin_peers","params":[],"id":1}' 2>/dev/null) # Check if we got a valid response if echo "$response" | jq -e '.result' > /dev/null 2>&1; then peer_count=$(echo "$response" | jq -r '.result | length') echo "$path: $peer_count peer(s)" + # Show running client version if available + if [ -n "$running_client_version" ]; then + echo " Running client: $running_client_version" + fi + # Extract and aggregate client version statistics if [ "$peer_count" -gt 0 ]; then # Extract client names and versions from peer data @@ -68,32 +87,79 @@ for path in $pathlist; do # Display client version statistics if [ ${#client_versions[@]} -gt 0 ]; then - echo " Client versions:" + echo " Peer client versions:" # Sort by count (descending), then by client name for client_version in "${!client_versions[@]}"; do count=${client_versions[$client_version]} printf "%3d %s\n" "$count" "$client_version" done | sort -rn | while read count client_version; do - printf " %-40s %3d peer(s)\n" "$client_version" "$count" + # Check if this matches the running client version + marker="" + if [ -n "$running_client_version" ] && [ "$client_version" = "$running_client_version" ]; then + marker=" (current)" + fi + printf " %-40s %3d peer(s)%s\n" "$client_version" "$count" "$marker" done + + # Check for newer versions and suggest updates + if [ -n "$running_client_version" ]; then + running_client=$(echo "$running_client_version" | cut -d'/' -f1) + running_version=$(echo "$running_client_version" | cut -d'/' -f2) + + # Find different versions of the same client + different_versions=() + for client_version in "${!client_versions[@]}"; do + peer_client=$(echo "$client_version" | cut -d'/' -f1) + peer_version=$(echo "$client_version" | cut -d'/' -f2) + + # Only compare if it's the same client with a different version + if [ "$peer_client" = "$running_client" ] && [ "$peer_version" != "$running_version" ]; then + different_versions+=("$client_version") + fi + done + + if [ ${#different_versions[@]} -gt 0 ]; then + echo " ℹ️ Different versions detected: Peers are running different versions of $running_client" + for diff_version in "${different_versions[@]}"; do + count=${client_versions[$diff_version]} + echo " $diff_version ($count peer(s))" + done + echo " Your version: $running_client_version" + fi + fi fi fi echo "" else + # Check if this is a method not found error (consensus client or admin API disabled) + error_code=$(echo "$response" | jq -r '.error.code // empty' 2>/dev/null) + error_msg=$(echo "$response" | jq -r '.error.message // empty' 2>/dev/null) + + # Skip silently if it's a method not found error (likely consensus client) + if [ -n "$error_code" ] && [ "$error_code" != "null" ]; then + # This is likely a consensus client endpoint, skip it silently + continue + fi + # Fallback to net_peerCount if admin_peers is not available response=$(curl --ipv4 -L -s -X POST "$RPC_URL" \ -H "Content-Type: application/json" \ - --data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":1}') + --data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":1}' 2>/dev/null) if echo "$response" | jq -e '.result' > /dev/null 2>&1; then peer_count=$(echo "$response" | jq -r '.result' | xargs printf "%d") echo "$path: $peer_count peer(s)" + if [ -n "$running_client_version" ]; then + echo " Running client: $running_client_version" + fi echo "" else - # If both methods fail, show error - error_msg=$(echo "$response" | jq -r '.error.message // "Unknown error"' 2>/dev/null || echo "Connection failed") - echo "$path: ERROR - $error_msg" - echo "" + # Only show error if it's not a method not found (skip consensus clients silently) + error_code=$(echo "$response" | jq -r '.error.code // empty' 2>/dev/null) + if [ -z "$error_code" ] || [ "$error_code" = "null" ]; then + # Connection error or other non-method error, skip silently + continue + fi fi fi fi