{"id":7455,"date":"2026-05-25T11:24:01","date_gmt":"2026-05-25T09:24:01","guid":{"rendered":"https:\/\/entropie.org\/3615\/?p=7455"},"modified":"2026-05-25T11:40:00","modified_gmt":"2026-05-25T09:40:00","slug":"scanner-son-reseau-local","status":"publish","type":"post","link":"https:\/\/entropie.org\/3615\/index.php\/2026\/05\/25\/scanner-son-reseau-local\/","title":{"rendered":"Scanner son r\u00e9seau local"},"content":{"rendered":"<p>Nom du fichier : ScanReseauLocal.sh<\/p>\n<pre>\r\n#!\/bin\/bash\r\n\r\n# Si on n'est pas dans un terminal, se relancer dans mate-terminal\r\nif ! [ -t 1 ]; then\r\n    mate-terminal -- bash -c \"sudo bash '$0'; exec bash\"\r\n    exit\r\nfi\r\n\r\n# =============================================================\r\n#  ScanReseauLocal.sh \u2014 Scanner r\u00e9seau local (Debian)\r\n#  D\u00e9pendances : nmap  \u2192  sudo apt install nmap\r\n# =============================================================\r\n\r\n# Utilisation :\r\n\r\n# Scan automatique (d\u00e9tecte ton r\u00e9seau tout seul)\r\n# sudo ~\/Bureau\/ScanReseauLocal.sh\r\n\r\n# Scan sur une plage personnalis\u00e9e\r\n# sudo ~\/Bureau\/ScanReseauLocal.sh 192.168.1.0\/24\r\n\r\n# Scan + ports ouverts d'un appareil pr\u00e9cis\r\n#\u00a0sudo ~\/Bureau\/ScanReseauLocal.sh --ports 192.168.0.42\r\n\r\nset -uo pipefail\r\n\r\n# \u2500\u2500 Couleurs \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nBOLD='\\033[1m'\r\nCYAN='\\033[0;36m'\r\nGREEN='\\033[0;32m'\r\nORANGE='\\033[38;5;214m'\r\nRED='\\033[0;31m'\r\nNC='\\033[0m'\r\n\r\n# \u2500\u2500 V\u00e9rifications pr\u00e9alables \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\ncheck_deps() {\r\n    local missing=()\r\n    for cmd in nmap ip; do\r\n        command -v \"$cmd\" &>\/dev\/null || missing+=(\"$cmd\")\r\n    done\r\n    if [[ ${#missing[@]} -gt 0 ]]; then\r\n        echo -e \"${RED}D\u00e9pendances manquantes : ${missing[*]}${NC}\"\r\n        echo -e \"Installe-les avec : ${ORANGE}sudo apt install nmap iproute2${NC}\"\r\n        exit 1\r\n    fi\r\n}\r\n\r\n# \u2500\u2500 D\u00e9tection automatique du r\u00e9seau actif \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\ndetect_network() {\r\n    local cidr\r\n    cidr=$(ip -4 addr show scope global \\\r\n           | grep -oP '(?<=inet\\s)\\d+\\.\\d+\\.\\d+\\.\\d+\/\\d+' \\\r\n           | head -1)\r\n\r\n    if [[ -z \"$cidr\" ]]; then\r\n        echo -e \"${RED}Impossible de d\u00e9tecter le r\u00e9seau. V\u00e9rif ta connexion.${NC}\"\r\n        exit 1\r\n    fi\r\n    echo \"$cidr\"\r\n}\r\n\r\n# \u2500\u2500 Scan principal \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nscan_network() {\r\n    local cidr=\"$1\"\r\n\r\n    echo\r\n    echo -e \"${BOLD}${CYAN}\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550${NC}\"\r\n    echo -e \"${BOLD}${CYAN}   \ud83d\udd0d  SCAN R\u00c9SEAU LOCAL                  ${NC}\"\r\n    echo -e \"${BOLD}${CYAN}\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550${NC}\"\r\n    echo -e \"  Plage cible : ${ORANGE}${cidr}${NC}\"\r\n    echo -e \"  D\u00e9marr\u00e9 le  : $(date '+%d\/%m\/%Y %H:%M:%S')\"\r\n    echo -e \"${BOLD}${CYAN}\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550${NC}\"\r\n    echo\r\n\r\n    local raw\r\n    raw=$(sudo nmap -sn -T4 \\\r\n        -PE -PP \\\r\n        -PS21,22,23,25,80,443,445,3389,8080 \\\r\n        -PA80,443 \\\r\n        -PR \\\r\n        \"$cidr\" 2>\/dev\/null)\r\n\r\n    local count=0\r\n\r\n    while IFS= read -r line; do\r\n        if [[ \"$line\" =~ ^\"Nmap scan report for \" ]]; then\r\n            local host=\"${line#Nmap scan report for }\"\r\n            local ip hostname\r\n            local regex='\\(([^)]+)\\)$'\r\n            if [[ \"$host\" =~ $regex ]]; then\r\n                hostname=\"${host%% (*}\"\r\n                ip=\"${BASH_REMATCH[1]}\"\r\n            else\r\n                ip=\"$host\"\r\n                hostname=\"\"\r\n            fi\r\n\r\n            local mac vendor mac_line\r\n            mac_line=$(echo \"$raw\" | grep -A3 \"^Nmap scan report for ${host}$\" \\\r\n                        | grep \"MAC Address\" || true)\r\n            if [[ -n \"$mac_line\" ]]; then\r\n                mac=$(echo \"$mac_line\" | awk '{print $3}')\r\n                vendor=$(echo \"$mac_line\" | sed 's\/.*(\\(.*\\))\/\\1\/')\r\n            else\r\n                mac=\"N\/A (machine locale ou acc\u00e8s limit\u00e9)\"\r\n                vendor=\"\"\r\n            fi\r\n\r\n            count=$(( count + 1 ))\r\n            echo -e \"  ${BOLD}${GREEN}\u25b8 Appareil #${count}${NC}\"\r\n            echo -e \"    IP       : ${ORANGE}${ip}${NC}\"\r\n            [[ -n \"$hostname\" ]] && \\\r\n                echo -e \"    Hostname : ${CYAN}${hostname}${NC}\"\r\n            echo -e \"    MAC      : ${mac}\"\r\n            [[ -n \"$vendor\" ]] && \\\r\n                echo -e \"    Fabricant: ${vendor}\"\r\n            echo\r\n        fi\r\n    done <<< \"$raw\"\r\n\r\n    echo -e \"${BOLD}${CYAN}\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550${NC}\"\r\n    echo -e \"  ${BOLD}${GREEN}${count} appareil(s) d\u00e9tect\u00e9(s)${NC}\"\r\n    echo -e \"${BOLD}${CYAN}\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550${NC}\"\r\n    echo\r\n}\r\n\r\n# \u2500\u2500 Optionnel : scan de ports sur un appareil \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nscan_ports() {\r\n    local ip=\"$1\"\r\n    echo\r\n    echo -e \"${BOLD}${CYAN}\u2500\u2500 Scan des ports ouverts sur ${ip} \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500${NC}\"\r\n    sudo nmap -T4 --open --top-ports 100 \"$ip\" 2>\/dev\/null \\\r\n        | grep -E \"^[0-9]+\/(tcp|udp)|Nmap scan\" \\\r\n        | sed \"s\/^\/  \/\"\r\n    echo\r\n}\r\n\r\n# \u2500\u2500 Point d'entr\u00e9e \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\nmain() {\r\n    check_deps\r\n\r\n    local cidr=\"${1:-}\"\r\n    local port_ip=\"\"\r\n\r\n    while [[ $# -gt 0 ]]; do\r\n        case \"$1\" in\r\n            --ports)\r\n                port_ip=\"${2:-}\"\r\n                shift 2\r\n                ;;\r\n            *)\r\n                cidr=\"$1\"\r\n                shift\r\n                ;;\r\n        esac\r\n    done\r\n\r\n    [[ -z \"$cidr\" ]] && cidr=$(detect_network)\r\n\r\n    scan_network \"$cidr\"\r\n\r\n    if [[ -n \"$port_ip\" ]]; then\r\n        scan_ports \"$port_ip\"\r\n    fi\r\n}\r\n\r\nmain \"$@\"\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Nom du fichier : ScanReseauLocal.sh #!\/bin\/bash # Si on n&rsquo;est pas dans un terminal, se relancer dans mate-terminal if ! [ -t 1 ]; then mate-terminal &#8212; bash -c \u00ab\u00a0sudo bash &lsquo;$0&rsquo;; exec bash\u00a0\u00bb exit fi # ============================================================= # ScanReseauLocal.sh \u2014 Scanner r\u00e9seau local (Debian) # D\u00e9pendances : nmap \u2192 sudo apt install nmap # &hellip; <a href=\"https:\/\/entropie.org\/3615\/index.php\/2026\/05\/25\/scanner-son-reseau-local\/\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;Scanner son r\u00e9seau local&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[],"class_list":["post-7455","post","type-post","status-publish","format-standard","hentry","category-bash"],"_links":{"self":[{"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/posts\/7455"}],"collection":[{"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/comments?post=7455"}],"version-history":[{"count":4,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/posts\/7455\/revisions"}],"predecessor-version":[{"id":7459,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/posts\/7455\/revisions\/7459"}],"wp:attachment":[{"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/media?parent=7455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/categories?post=7455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/tags?post=7455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}