#!/bin/bash

# Simple host connectivity test
# Tests each host from all_hosts.txt individually

echo "=== SIMPLE HOST CONNECTIVITY TEST ==="
echo "Testing each host from: comprehensive_discovery_results/all_hosts.txt"
echo

# Test each host
while IFS=: read -r host user; do
    if [[ -z "$host" || "$host" == "localhost" ]]; then
        continue
    fi
    
    echo "🔍 Testing: $host (user: $user)"
    
    # Test basic ping
    echo "   Testing ping..."
    if ping -c 1 -W 3 "$host" >/dev/null 2>&1; then
        echo "✅ Ping: SUCCESS"
    else
        echo "❌ Ping: FAILED"
        echo "   (This might be a DNS resolution issue)"
    fi
    
    # Test SSH connection (without password)
    echo "   Testing SSH connection..."
    if timeout 5 ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no "$user@$host" "echo 'SSH test'" 2>/dev/null; then
        echo "✅ SSH: SUCCESS (no password needed)"
    else
        echo "❌ SSH: FAILED (password required or connection failed)"
    fi
    
    echo "---"
done < "comprehensive_discovery_results/all_hosts.txt"

echo "=== CONNECTIVITY TEST COMPLETE ==="
