#!/bin/bash # Get the current public IP address. NEW_IP=$(curl -s https://ipv4.sequoia.sh) echo "$NEW_IP" # Check if the file containing the last IP exists. if [ ! -f "$LAST_IP_FILE" ]; then echo "Last IP file not found. Creating a new one and updating DNS." # Write the new IP to the file for the first run. echo "$NEW_IP" > "$LAST_IP_FILE" LAST_IP="" # Treat this as a change else # Read the last stored IP address. LAST_IP=$(cat "$LAST_IP_FILE") fi # Compare the current IP with the last stored IP. if [ "$NEW_IP" != "$LAST_IP" ]; then # --- IP has changed --- echo "IP has changed from $LAST_IP to $NEW_IP. Updating DNS and sending email." # Update the DNS zone files using the new IP. # The 'template' command requires the full path. echo "$NEW_IP" | template --stdin --stdin --stdin --stdin /var/www/lakefox/build/zones/lakefox.net > /etc/bind/zones/lakefox.net echo "$NEW_IP" | template --stdin /var/www/lakefox/build/zones/asftp.sh > /etc/bind/zones/asftp.sh echo "$NEW_IP" | template --stdin /var/www/lakefox/build/zones/grimui.com > /etc/bind/zones/grimui.com echo "$NEW_IP" | template --stdin /var/www/lakefox/build/zones/decode.sh > /etc/bind/zones/decode.sh echo "$NEW_IP" | template --stdin /var/www/lakefox/build/zones/szn.io > /etc/bind/zones/szn.io echo "$NEW_IP" | template --stdin /var/www/lakefox/build/zones/lfx.lol > /etc/bind/zones/lfx.lol # Reload the BIND DNS server. systemctl reload bind9 # Update the stored IP address for the next run. echo "$NEW_IP" > "$LAST_IP_FILE" # Send an email with the new IP address. # Format for .ipnotify.env # /home/$USER/.ipnotify.env (or any path you like) # SMTP_USER='email@email.com' # SMTP_PASS='your-app-password' # SMTP_HOST='smtp.gmail.com' # SMTP_PORT='465' # 465 = SMTPS, 587 = STARTTLS # --- load secrets --- source /home/$USER/.ipnotify.env # --- send via curl --- curl --ssl-reqd \ --url "smtps://${SMTP_HOST}:${SMTP_PORT}" \ --user "${SMTP_USER}:${SMTP_PASS}" \ --mail-from "${SMTP_USER}" \ --mail-rcpt "${EMAIL_ADDRESS}" \ --upload-file - <<<"From: ${SMTP_USER} To: ${EMAIL_ADDRESS} Subject: Public IP Address Changed New IP Address: ${NEW_IP} " else # --- IP is the same --- echo "IP address has not changed ($NEW_IP). No action taken." fi