show_netowrk-ip_docker.sh
· 979 B · Bash
Raw
#!/bin/bash
# show_netowrk-ip_docker.sh
# By Erreur32 2025
# Fonction pour afficher un tableau bien aligné
function print_table {
local network_name="$1"
# Récupération des conteneurs et IPs
local results=$(docker network inspect "$network_name" --format '{{range .Containers}}{{printf "%-30s %-20s\n" .Name .IPv4Address}}{{end}}')
# Vérifier si le réseau contient des conteneurs
if [[ -z "$results" ]]; then
echo -e "\033[33m🔹 Réseau: $network_name (Aucun conteneur attaché)\033[0m"
else
echo -e "\n\033[32m🔹 Réseau: $network_name\033[0m"
echo "---------------------------------------------"
printf "%-30s %-20s\n" "CONTAINER" "IP ADDRESS"
echo "---------------------------------------------"
echo "$results"
fi
}
# Lister tous les réseaux Docker
networks=$(docker network ls --format '{{.Name}}')
# Afficher les résultats
for net in $networks; do
print_table "$net"
done
| 1 | #!/bin/bash |
| 2 | |
| 3 | # show_netowrk-ip_docker.sh |
| 4 | # By Erreur32 2025 |
| 5 | |
| 6 | # Fonction pour afficher un tableau bien aligné |
| 7 | function print_table { |
| 8 | local network_name="$1" |
| 9 | |
| 10 | # Récupération des conteneurs et IPs |
| 11 | local results=$(docker network inspect "$network_name" --format '{{range .Containers}}{{printf "%-30s %-20s\n" .Name .IPv4Address}}{{end}}') |
| 12 | |
| 13 | # Vérifier si le réseau contient des conteneurs |
| 14 | if [[ -z "$results" ]]; then |
| 15 | echo -e "\033[33m🔹 Réseau: $network_name (Aucun conteneur attaché)\033[0m" |
| 16 | else |
| 17 | echo -e "\n\033[32m🔹 Réseau: $network_name\033[0m" |
| 18 | echo "---------------------------------------------" |
| 19 | printf "%-30s %-20s\n" "CONTAINER" "IP ADDRESS" |
| 20 | echo "---------------------------------------------" |
| 21 | echo "$results" |
| 22 | fi |
| 23 | } |
| 24 | |
| 25 | # Lister tous les réseaux Docker |
| 26 | networks=$(docker network ls --format '{{.Name}}') |
| 27 | |
| 28 | # Afficher les résultats |
| 29 | for net in $networks; do |
| 30 | print_table "$net" |
| 31 | done |
| 32 |