Last active 1718449842

lerone revised this gist 1718449842. Go to revision

1 file changed, 1 insertion

Offene Docker-Ports

@@ -61,5 +61,6 @@ while read -r line; do
61 61 done <<< "$docker_output"
62 62
63 63 # Sort and print output
64 + echo -e "All green ports are locally open \n and all red Ports a available from the bad bad internet \n"
64 65 echo -e "$exposed_output"
65 66 echo -e "$not_exposed_output"

lerone revised this gist 1718449528. Go to revision

1 file changed, 0 insertions, 0 deletions

Offende Docker-Ports renamed to Offene Docker-Ports

File renamed without changes

lerone revised this gist 1718448074. Go to revision

1 file changed, 65 insertions

Offende Docker-Ports (file created)

@@ -0,0 +1,65 @@
1 + #!/bin/bash
2 +
3 + # ANSI color codes
4 + RED='\033[0;31m'
5 + GREEN='\033[0;32m'
6 + NC='\033[0m' # No Color
7 +
8 + # Initialize output variables and max length
9 + exposed_output=""
10 + not_exposed_output=""
11 + max_length=0
12 + color_blind_mode=0
13 +
14 + # Check for color-blind mode flag
15 + if [[ "$1" == "--i-am-colorblind" ]]; then
16 + color_blind_mode=1
17 + fi
18 +
19 + # Get Docker container info
20 + docker_output=$(docker ps --format '{{.Names}}\t{{.Ports}}')
21 +
22 + # First pass to find the longest container name
23 + while 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
29 + done <<< "$docker_output"
30 +
31 + # Second pass to generate the output
32 + while 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
61 + done <<< "$docker_output"
62 +
63 + # Sort and print output
64 + echo -e "$exposed_output"
65 + echo -e "$not_exposed_output"
Newer Older