#!/bin/bash # Check if required arguments are provided if [ $# -ne 2 ]; then echo "Usage: $0 " 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"