Created
July 22, 2026 22:10
-
-
Save NQevxvEtg/cf328f6b559d335d1d5d0bd908a4356a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| if [[ $# -lt 1 ]]; then | |
| echo "Usage: $0 <file>" | |
| exit 1 | |
| fi | |
| FILE="$1" | |
| if [[ ! -f "$FILE" ]]; then | |
| echo "File not found: $FILE" | |
| exit 1 | |
| fi | |
| # prefer 'dig' if available, otherwise fall back to 'host' | |
| if command -v dig &>/dev/null; then | |
| while IFS= read -r line; do | |
| name="${line#"${line%%[![:space:]]*}"}" # trim leading whitespace | |
| name="${name%"${name##*[![:space:]]}"}" # trim trailing whitespace | |
| [[ -z "$name" || "$name" == \#* ]] && continue | |
| ips=$(dig +short A "$name" 2>/dev/null) | |
| if [[ -n "$ips" ]]; then | |
| printf "%s -> %s\n" "$name" "$(echo "$ips" | paste -sd ', ')" | |
| else | |
| printf "%s -> [no record]\n" "$name" | |
| fi | |
| done < "$FILE" | |
| elif command -v host &>/dev/null; then | |
| while IFS= read -r line; do | |
| name="${line#"${line%%[![:space:]]*}"}" | |
| name="${name%"${name##*[![:space:]]}"}" | |
| [[ -z "$name" || "$name" == \#* ]] && continue | |
| out=$(host "$name" 2>/dev/null) || true | |
| if echo "$out" | grep -q "has address"; then | |
| ips=$(echo "$out" | grep "has address" | awk '{print $NF}' | paste -sd ', ') | |
| printf "%s -> %s\n" "$name" "$ips" | |
| else | |
| printf "%s -> [no record]\n" "$name" | |
| fi | |
| done < "$FILE" | |
| else | |
| echo "Neither 'dig' nor 'host' found — install bind-tools or dnsutils" | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment