All checks were successful
continuous-integration/drone/push Build is passing
29 lines
520 B
Bash
29 lines
520 B
Bash
|
|
#!/usr/bin/env bash
|
|
|
|
LOCAL_REAL_IP=$(hostname -I 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i !~ /^127\./) {print $i; exit}}')
|
|
|
|
# Split comma-separated list into array
|
|
IFS=',' read -ra HOSTS <<< "$1"
|
|
|
|
for host in "${HOSTS[@]}"; do
|
|
# Resolve hostname to IP (IPv4)
|
|
ip=$(getent hosts "$host" | awk '{print $1}')
|
|
|
|
case "$ip" in
|
|
127.*|::1)
|
|
if [ -z "$LOCAL_REAL_IP" ]; then
|
|
echo "$ip"
|
|
else
|
|
echo "$LOCAL_REAL_IP"
|
|
fi
|
|
;;
|
|
"")
|
|
echo "#$host (resolve failed)"
|
|
;;
|
|
*)
|
|
echo "$ip"
|
|
;;
|
|
esac
|
|
done
|