Files
esn-support-bash-snippets/legacy/getIps/getIps.sh
T
2025-09-15 12:04:43 +02:00

29 lines
645 B
Bash

#!/bin/bash
# Check if required arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <input_file> <output_file>"
echo "Example: $0 hosts.txt output.txt"
exit 1
fi
# Input and output files from command line arguments
INPUT_FILE="$1"
OUTPUT_FILE="$2"
# Clear previous output
> "$OUTPUT_FILE"
# Process each hostname
while read -r host; do
# Skip empty lines
[[ -z "$host" ]] && continue
ipv4=$(dig +short A "$host" | head -n 1)
ipv6=$(dig +short AAAA "$host" | head -n 1)
echo -e "$host\t${ipv4:-N/A}\t${ipv6:-N/A}" >> "$OUTPUT_FILE"
done < "$INPUT_FILE"
echo "Done. Results written to $OUTPUT_FILE"