#!/bin/bash
# Comprehensive search for device using 192.168.11.14

IP="192.168.11.14"
MAC="bc:24:11:ee:a6:ec"

echo "=== Comprehensive Device Search for $IP ==="
echo "MAC Address: $MAC"
echo ""

echo "1. Checking Proxmox cluster containers..."
for host in 192.168.11.10 192.168.11.11 192.168.11.12; do
  echo "   Checking $host..."
  ssh -o ConnectTimeout=3 root@$host "pct list --all 2>/dev/null | while read line; do
    vmid=\$(echo \$line | awk '{print \$1}')
    [ -n \"\$vmid\" ] && [ \"\$vmid\" != \"VMID\" ] && pct config \$vmid 2>/dev/null | grep -q '$IP\|$MAC' && echo \"      Found in VMID \$vmid\" && pct config \$vmid 2>/dev/null | grep -E 'name=|net0=' | head -2
  done" 2>/dev/null
done

echo ""
echo "2. Checking network interfaces..."
for host in 192.168.11.10 192.168.11.11 192.168.11.12; do
  echo "   Checking $host..."
  ssh -o ConnectTimeout=3 root@$host "ip addr show | grep -A 2 '$IP' && echo '      Found interface with $IP'" 2>/dev/null || echo "      No interface found"
done

echo ""
echo "3. Checking ARP/neighbor tables..."
for host in 192.168.11.10 192.168.11.11 192.168.11.12; do
  echo "   Checking $host..."
  ssh -o ConnectTimeout=3 root@$host "ip neigh show $IP 2>/dev/null || arp -n $IP 2>/dev/null || echo '      No ARP entry'" 2>/dev/null
done

echo ""
echo "4. Omada Controller (192.168.11.20:8043)"
echo "   Note: Requires web interface or API access to query devices"
echo "   Access: https://192.168.11.20:8043"

echo ""
echo "=== Search Complete ==="
