#!/bin/bash # Vérifie si une IP est fournie if [ -z "$1" ]; then echo "Usage: $0 " exit 1 fi IP="$1" echo "🔍 Recherche du nom d'hôte pour l'IP : $IP" # Fonction pour vérifier si une commande est disponible command_exists() { command -v "$1" &> /dev/null } # 1️⃣ Test LLMNR (Link-Local Multicast Name Resolution) if command_exists resolvectl; then HOSTNAME_LLMNR=$(resolvectl query "$IP" 2>/dev/null | grep -oP '(?<=Name:\s).*' | head -n1) if [ ! -z "$HOSTNAME_LLMNR" ]; then echo "✅ LLMNR: $HOSTNAME_LLMNR" exit 0 fi else echo "⚠ LLMNR non disponible (resolvectl absent)" fi # 2️⃣ Test mDNS (Multicast DNS / Avahi) if command_exists avahi-resolve; then HOSTNAME_MDNS=$(avahi-resolve -a "$IP" 2>/dev/null | awk '{print $2}') if [ ! -z "$HOSTNAME_MDNS" ]; then echo "✅ mDNS (Avahi): $HOSTNAME_MDNS" exit 0 fi else echo "⚠ mDNS non disponible (avahi-resolve absent)" fi # 3️⃣ Vérification du cache ARP if command_exists arp; then HOSTNAME_ARP=$(arp -a | grep "$IP" | awk '{print $1}') if [ ! -z "$HOSTNAME_ARP" ]; then echo "✅ ARP: $HOSTNAME_ARP" exit 0 fi else echo "⚠ ARP non disponible" fi # 4️⃣ Vérification via NetBIOS (Windows/Samba) if command_exists nmblookup; then HOSTNAME_NETBIOS=$(nmblookup -A "$IP" 2>/dev/null | grep -m1 '<00>' | awk '{print $1}') if [ ! -z "$HOSTNAME_NETBIOS" ]; then echo "✅ NetBIOS: $HOSTNAME_NETBIOS" exit 0 fi else echo "⚠ NetBIOS non disponible (nmblookup absent)" fi # 5️⃣ Scan réseau avec Nmap pour identifier l'hôte if command_exists nmap; then HOSTNAME_NMAP=$(nmap -sP "$IP" 2>/dev/null | grep "Nmap scan report" | awk '{print $5}') if [ ! -z "$HOSTNAME_NMAP" ]; then echo "✅ Nmap: $HOSTNAME_NMAP" exit 0 fi else echo "⚠ Nmap non disponible" fi echo "❌ Aucune correspondance trouvée." exit 1