Feat: Laget is_reachable in eigene Datei aus

This commit is contained in:
DragonSlayer_14 2025-03-05 19:21:03 +01:00
parent cdca7c2901
commit a7be7b39b6
2 changed files with 26 additions and 17 deletions

24
Utility/IsReachable.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
# === IMPORTS ===
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/Log.sh"
# === Funktionen ===
is_reachable() {
local device_ip="$1"
local max_retries="$2" # Zweiter Parameter gibt die Anzahl der Versuche an
for ((i = 1; i<=max_retries; i++)); do
log "Teste Erreichbarkeit von $device_ip - Versuch $i/$max_retries..."
if ping -c 1 -W 2 "$device_ip" &>/dev/null; then
log "Gerät $device_ip ist erreichbar."
return 0
fi
sleep "$PING_WAIT"
done
log "Gerät $device_ip ist NICHT erreichbar."
return 1
}

19
Utility/WakeOnLan.sh Executable file → Normal file
View File

@ -3,6 +3,8 @@
# === IMPORTS ===
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/NetworkCheck.sh"
source "$SCRIPT_DIR/IsReachable.sh"
source "$SCRIPT_DIR/IpFromMac.sh"
source "$SCRIPT_DIR/Log.sh"
# === KONFIGURATION ===
@ -14,23 +16,6 @@ WOL_WAIT=60 # Wartezeit nach WOL (Sekunden)
# === FUNKTIONEN ===
is_reachable() {
local device_ip="$1"
local max_retries="$2" # Zweiter Parameter gibt die Anzahl der Versuche an
for ((i = 1; i<=max_retries; i++)); do
log "Teste Erreichbarkeit von $device_ip - Versuch $i/$max_retries..."
if ping -c 1 -W 2 "$device_ip" &>/dev/null; then
log "Gerät $device_ip ist erreichbar."
return 0
fi
sleep "$PING_WAIT"
done
log "Gerät $device_ip ist NICHT erreichbar."
return 1
}
send_wol() {
local device_mac="$1"
log "Sende Wake-on-LAN Signal an $device_mac..."