#!/bin/bash # NameCheap Dynamic IP Domain Sync Script # For Multiple Records / Sub Domains # By Ben A - LOSTGEEK.NET - 2024 # Provide your info DOMAIN="domain.com" PASSKEY="xxxxxxxxxxxxxxx" SUBDOMS=("@" "www" "ben") # All Sub-Domains. "@" = Domain w/o prefix. # We get IP for domain, and WAN IP... DOMIP=$(ping -c1 $DOMAIN | sed -nE 's/^.*\(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\).*$/\1/p' | head -n 1) WANIP=$(curl -s checkip.amazonaws.com) DTSTA=$(date +"%Y%m%d_%H%M%S") ## Line below works on router/firewall # WANIP=$(ifconfig wan | awk '/inet / {print $2}' | cut -d: -f2) # debug ... echo $DOMIP " is DOMIP" echo $WANIP " is WANIP" echo # # Check for --force argument if [[ "$1" == "--force" ]]; then # We skip check... echo "Attempting update(s) for $DOMAIN..." else if [ "$WANIP" == "$DOMIP" ]; then echo "Domain already set to correct address, NO ACTION NEEDED exiting..." # Now, we log that we ran... (and didn't need to do anything!) echo $DTSTA " -- NO ACTION, DOMAIN GOOD" >> /home/ben/scripts/cron/namecheap.log exit 0 fi fi echo "Wan IP: $WANIP ... $DOMAIN = $DOMIP ... Will Try Update ..." # Of course, we log that we did run! echo $DTSTA " -- IP MISMATCH OR FORCED UPDATE!! SEE INFO:" >> /home/ben/scripts/cron/namecheap.log echo $DTSTA " -- " $DOMAIN " was set to " $DOMIP " , and WAN IP was " $WANIP "!!" >> /home/ben/scripts/cron/namecheap.log # Will loop, to update each name... for SUBDOM in "${SUBDOMS[@]}"; do curl "https://dynamicdns.park-your-domain.com/update?host=$SUBDOM&domain=$DOMAIN&password=$PASSKEY&ip=$WANIP" sleep 1 done exit