Skip to content

Instantly share code, notes, and snippets.

@Lovinoes
Created August 13, 2025 19:22
Show Gist options
  • Save Lovinoes/cf8d226a5fb68e51220eceb69a6a6e53 to your computer and use it in GitHub Desktop.
Save Lovinoes/cf8d226a5fb68e51220eceb69a6a6e53 to your computer and use it in GitHub Desktop.
Kleines Bash Skript für MTR, Traceroute und iPerf3 Netzwerktests mit Logging - privat genutzt zur Dokumentation von Vodafone Problemen
#!/bin/bash
# Netzwerktest Skript
# Ablauf: MTR/Traceroute (1/2) -> iPerf3 Download & Upload (mit Fallback je group) -> MTR/Traceroute (2/2)
# Logs: $HOME/Dokumente/Vodafone/Logs/<TT.MM.YYYY>/LOG-HH-MM-SS.txt
# Errors: $HOME/Dokumente/Vodafone/Logs/Errors/<TT.MM.YYYY>/ERROR-HH-MM-SS.log
#
# Credits: Script by @lovinoes & ChatGPT 5.0
#
set -Euo pipefail
trap 'tput cnorm 2>/dev/null || true; exit' EXIT
trap 'ec=$?; error_handler $LINENO "$BASH_COMMAND" "$ec"' ERR
GRN=$'\e[32m'
RED=$'\e[31m'
WHT=$'\e[37m'
LHTBLU=$'\e[94m'
NC=$'\e[0m'
BASE_DIR="$HOME/Dokumente/Vodafone/Logs"
TODAY="$(date +"%d.%m.%Y")"
TIME_NOW="$(date +"%H-%M-%S")"
DAY_DIR="$BASE_DIR/$TODAY"
ERROR_DIR="$BASE_DIR/Errors/$TODAY"
mkdir -p "$DAY_DIR" "$ERROR_DIR"
LOG_FILE="$DAY_DIR/LOG-$TIME_NOW.txt"
ERROR_FILE="$ERROR_DIR/ERROR-$TIME_NOW.log"
MTR_TARGETS=("8.8.8.8" "1.1.1.1" "9.9.9.9" "208.67.222.222")
TRACEROUTE_TARGETS=("8.8.8.8" "1.1.1.1" "9.9.9.9" "208.67.222.222")
error_handler() {
local line="$1"
local cmd="$2"
local ec="${3:-1}"
if [[ "$ec" -ne 0 ]]; then
{
echo "=== FEHLER AUFGETRETEN ==="
echo "Zeit: $(date)"
echo "Zeile: $line"
echo "Befehl: $cmd"
echo "Exitcode: $ec"
echo "=========================="
echo
} >> "$ERROR_FILE"
fi
}
banner() {
local title="$1"
{
echo "#"
echo "#"
echo "#"
echo "#"
echo "# $title"
echo "#"
echo "#"
echo "#"
echo "#"
} >> "$LOG_FILE"
}
animate_dots() {
local pid="$1"
local prefix="$2"
local i=0
tput civis 2>/dev/null || true
while kill -0 "$pid" 2>/dev/null; do
local dots_count=$(( (i % 3) + 1 ))
local dots
dots=$(printf "%.*s" "$dots_count" "...")
printf "\r%s%s " "$prefix" "$dots"
sleep 0.5
((i++))
done
printf "\r%s " "$prefix"
}
clear_eol() { tput el 2>/dev/null || true; }
declare -A RESULTS
ORDERED_LABELS=()
run_cmd_with_animation() {
local label="$1"
local cmd_str="$2"
echo "===== $label =====" >> "$LOG_FILE"
( bash -lc "$cmd_str" >> "$LOG_FILE" 2>> "$ERROR_FILE" ) &
local pid=$!
animate_dots "$pid" "${GRN}${label}${NC} "
wait "$pid"
local rc=$?
if [[ $rc -eq 0 ]]; then
printf "\r%s ... " "${GRN}${label}${NC}"; clear_eol; printf "%bOK%b\n" "$GRN" "$NC"
RESULTS["$label"]="OK"
else
printf "\r%s ... " "${GRN}${label}${NC}"; clear_eol; printf "%bFAIL%b\n" "$RED" "$NC"
RESULTS["$label"]="FAIL ($cmd_str)"
fi
ORDERED_LABELS+=("$label")
}
IPERF_SERVERS=(
"# Deutschland, Berlin"
"a110.speedtest.wobcom.de -6"
"a209.speedtest.wobcom.de -6"
"# Deutschland, Düsseldorf"
"a208.speedtest.wobcom.de -6"
"# Deutschland, Frankfurt"
"178.215.228.109 -p 9204-9240 -u"
"185.102.219.93 -u"
"a205.speedtest.wobcom.de -6"
"a210.speedtest.wobcom.de -6"
"fra.speedtest.clouvider.net -p 5200-5209 -6 -u"
"spd-desrv.hostkey.com -p 5201-5209"
"speedtest.fra1.de.leaseweb.net -p 5201-5210 -6"
"speedtest.ip-projects.de -6 -u"
"# Deutschland, Norderstedt"
"speedtest.wtnet.de -p 5200-5209 -6 -u"
"speedtest.wtnet.de -p 5300-5309 -6 -u"
"# Deutschland, Wolfsburg"
"a400.speedtest.wobcom.de -6"
"speedtest.wobcom.de -6"
"# Luxemburg, Bissen"
"speedtest.lu.buyvm.net -6 -u"
"# Niederlande, Amsterdam"
"185.102.218.1 -u"
"a204.speedtest.wobcom.de -6"
"ams.speedtest.clouvider.net -p 5200-5209 -6 -u"
"iperf-ams-nl.eranium.net -p 5201-5210 -6 -u"
"lg.ams-nl.terrahost.com -p 9206-9240 -6 -u"
"ping-ams1.online.net -p 5200-5209 -u"
"speedtest.ams1.nl.leaseweb.net -p 5201-5210 -6"
"speedtest.ams1.novogara.net -p 5200-5209 -6 -u"
"speedtest.ams2.nl.leaseweb.net -p 5201-5210 -6"
"speedtest.nl3.mirhosting.net -p 5201-5210 -6 -u"
)
ensure_flag_R() {
local entry="$1"
read -r -a toks <<< "$entry"
local hasR=0
for t in "${toks[@]}"; do [[ "$t" == "-R" ]] && hasR=1; done
((hasR==0)) && toks+=("-R")
echo "${toks[*]}"
}
remove_flag_R() {
local entry="$1"
read -r -a toks <<< "$entry"
local out=()
for t in "${toks[@]}"; do [[ "$t" == "-R" ]] && continue; out+=("$t"); done
echo "${out[*]}"
}
run_iperf_groups() {
local current_group=""
local cmds=()
_run_group_direction() {
local group_label="$1"
local direction="$2"
local -n ref_cmds="$3"
local status_file; status_file="$(mktemp)"
local last_cmd_file; last_cmd_file="$(mktemp)"
(
set +e
echo "===== iPerf3 Gruppe: ${group_label} – ${direction} =====" >> "$LOG_FILE"
local had_error=0
local rc=1
local last_cmd=""
for ent in "${ref_cmds[@]}"; do
local args
if [[ "$direction" == "Download" ]]; then
args="$(ensure_flag_R "$ent")"
else
args="$(remove_flag_R "$ent")"
fi
local cmd="iperf3 -c $args"
echo "\$ $cmd" >> "$LOG_FILE"
bash -lc "$cmd" >> "$LOG_FILE" 2>> "$ERROR_FILE"
rc=$?
last_cmd="$cmd"
if [ $rc -eq 0 ]; then
break
else
had_error=1
fi
done
echo "$last_cmd" > "$last_cmd_file"
if (( had_error )); then
echo "FAIL" > "$status_file"
exit 1
else
echo "OK" > "$status_file"
exit $rc
fi
) &
local pid=$!
local label="[iPerf3] ${group_label} (${direction})"
animate_dots "$pid" "${GRN}${label}${NC} "
wait "$pid"
local rc=$?
local status="OK"
[[ -f "$status_file" ]] && status="$(cat "$status_file")"
rm -f "$status_file"
local last_cmd=""
[[ -f "$last_cmd_file" ]] && last_cmd="$(cat "$last_cmd_file")"
rm -f "$last_cmd_file"
if [[ "$status" == "OK" && $rc -eq 0 ]]; then
printf "\r%s ... " "${GRN}${label}${NC}"; tput el 2>/dev/null || true; printf "%bOK%b\n" "$GRN" "$NC"
RESULTS["$label"]="OK"
else
printf "\r%s ... " "${GRN}${label}${NC}"; tput el 2>/dev/null || true; printf "%bFAIL%b\n" "$RED" "$NC"
RESULTS["$label"]="FAIL (${last_cmd})"
fi
ORDERED_LABELS+=("$label")
}
for entry in "${IPERF_SERVERS[@]}"; do
if [[ "$entry" == \#* ]]; then
if [[ -n "$current_group" && ${#cmds[@]} -gt 0 ]]; then
_run_group_direction "$current_group" "Download" cmds
_run_group_direction "$current_group" "Upload" cmds
cmds=()
fi
current_group="${entry#\# }"
else
cmds+=("$entry")
fi
done
if [[ -n "$current_group" && ${#cmds[@]} -gt 0 ]]; then
_run_group_direction "$current_group" "Download" cmds
_run_group_direction "$current_group" "Upload" cmds
fi
}
clear
echo -e "${RED}root@netzwerktest${WHT}:${NC}${LHTBLU}~ #${NC} ${WHT}Starte Test am $(date +"%d.%m.%Y um %H:%M:%S Uhr.")${NC}"
sleep 1
banner "MTR Tests – Runde 1"
for tgt in "${MTR_TARGETS[@]}"; do
run_cmd_with_animation "[MTR] ${tgt} (1/2)" "mtr -rwc 20 ${tgt}"
done
banner "Traceroute Tests – Runde 1"
for tgt in "${TRACEROUTE_TARGETS[@]}"; do
run_cmd_with_animation "[Traceroute] ${tgt} (1/2)" "traceroute ${tgt}"
done
banner "Iperf Speedtests auf verschiedenen Servern"
run_iperf_groups
banner "MTR Tests – Runde 2"
for tgt in "${MTR_TARGETS[@]}"; do
run_cmd_with_animation "[MTR] ${tgt} (2/2)" "mtr -rwc 20 ${tgt}"
done
banner "Traceroute Tests – Runde 2"
for tgt in "${TRACEROUTE_TARGETS[@]}"; do
run_cmd_with_animation "[Traceroute] ${tgt} (2/2)" "traceroute ${tgt}"
done
echo
echo "===== TEST-ZUSAMMENFASSUNG ====="
for key in "${ORDERED_LABELS[@]}"; do
val="${RESULTS[$key]}"
if [[ "$val" == "OK" ]]; then
echo -e "$key: ${GRN}OK${NC}"
else
echo -e "$key: ${RED}${val}${NC}"
fi
done
echo "==============================="
echo "Log gespeichert: $LOG_FILE"
if [[ -s "$ERROR_FILE" ]]; then
events=$(grep -c "^=== FEHLER AUFGETRETEN ===" "$ERROR_FILE" 2>/dev/null || echo 0)
if (( events > 0 )); then
echo "Errors gespeichert: $ERROR_FILE ($events Ereignisse)"
else
echo "Errors gespeichert: $ERROR_FILE"
fi
else
rm -f "$ERROR_FILE" 2>/dev/null || true
echo -e "${GRN}0 Errors.${NC}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment