#!/bin/bash

# Define the domain name and the output file
DOMAIN="clutchbbs.com"  # Replace with the desired domain name
OUTPUT_FILE="/mystic/data/whitelist.txt"

# Get the current date and time
CURRENT_DATE=$(date '+%Y-%m-%d %H:%M:%S')

# Get the IP address of the domain
IP_ADDRESS=$(dig +short "$DOMAIN" | tail -n1)

# Check if the IP address was retrieved
if [ -z "$IP_ADDRESS" ]; then
    echo "Failed to retrieve IP address for $DOMAIN."
    exit 1
fi

# Check if the IP address is already in the output file
if ! grep -q "$IP_ADDRESS" "$OUTPUT_FILE"; then
    # Append the date and time and the IP address to the output file
    echo "; $DOMAIN" >> "$OUTPUT_FILE"
    echo "; $CURRENT_DATE" >> "$OUTPUT_FILE"
    echo "$IP_ADDRESS" >> "$OUTPUT_FILE"
    echo "IP address $IP_ADDRESS added to $OUTPUT_FILE."
else
    echo "IP address $IP_ADDRESS is already in $OUTPUT_FILE."
fi
