最后活跃于 1718449842

Offene Docker-Ports 原始文件
1#!/bin/bash
2
3# ANSI color codes
4RED='\033[0;31m'
5GREEN='\033[0;32m'
6NC='\033[0m' # No Color
7
8# Initialize output variables and max length
9exposed_output=""
10not_exposed_output=""
11max_length=0
12color_blind_mode=0
13
14# Check for color-blind mode flag
15if [[ "$1" == "--i-am-colorblind" ]]; then
16 color_blind_mode=1
17fi
18
19# Get Docker container info
20docker_output=$(docker ps --format '{{.Names}}\t{{.Ports}}')
21
22# First pass to find the longest container name
23while read -r line; do
24 container=$(echo -e "$line" | awk '{print $1}')
25 length=${#container}
26 if (( length > max_length )); then
27 max_length=$length
28 fi
29done <<< "$docker_output"
30
31# Second pass to generate the output
32while read -r line; do
33 container=$(echo -e "$line" | awk '{print $1}')
34 ports=$(echo -e "$line" | cut -f2-)
35
36 # Skip containers with no ports or no mappings
37 if [ -z "$ports" ] || [[ "$ports" == *"<->"* ]] || [[ ! "$ports" == *'->'* ]]; then
38 continue
39 fi
40
41 # Remove IP prefixes and trailing comma
42 ports=$(echo "$ports" | sed 's/0.0.0.0://g' | sed 's/127.0.0.1://g' | sed 's/,$//')
43
44 # Align output
45 padding=$(printf "%*s" $((max_length - ${#container})) "")
46
47 # Check if ports are exposed
48 if [[ "$line" == *"0.0.0.0:"* ]] || [[ "$line" == *":::"* ]]; then
49 if (( color_blind_mode )); then
50 exposed_output+="Exposed: ${container}${padding} : ${ports}\n"
51 else
52 exposed_output+="${RED}${container}${padding} : ${ports}${NC}\n"
53 fi
54 else
55 if (( color_blind_mode )); then
56 not_exposed_output+="Not Exposed: ${container}${padding} : ${ports}\n"
57 else
58 not_exposed_output+="${GREEN}${container}${padding} : ${ports}${NC}\n"
59 fi
60 fi
61done <<< "$docker_output"
62
63# Sort and print output
64echo -e "All green ports are locally open \n and all red Ports a available from the bad bad internet \n"
65echo -e "$exposed_output"
66echo -e "$not_exposed_output"