Page 1 of 1

[PHP][DDNS][Namecheap] Namecheap DDNS Update Script - Dynamic IP

Posted: Thu Dec 27, 2018 10:52 pm
by zAce
Namecheap DDNS Update Script - Dynamic IP

Go To Namecheap Account
Go To Domain List >> Manage >> Select Namecheap BasicDNS For Nameservers
Next Go To Advanced DNS >> Enable DYNAMIC DNS (Second Last Option If You Dont See It Then Its Because You Haven't Changed Nameservers)

Next Create Host @ With Any IP Or 127.0.0.1

Image

Image

Image

Image

Then Edit The namecheap.sh With Your Details

To Force Update Script Delete IP.txt File

cron
@reboot /home/path_to_namecheap/namecheap/c.sh or namecheap.sh
*/5 * * * * /home/path_to_namecheap/namecheap/c.sh or namecheap.sh


Code: Select all

#!/bin/bash

#Mood By DarkDroid - DD

#Namecheap Account Details
pass="7856eb48843443739642a29c60098175" # found in namecheap account settings
domain="yourdomain.com"
host="@"

#Getting IP
ip=$(curl -s https://ifconfig.me/)
ip_file="ip.txt"
log_file="namecheap.log"
update_file="update_details.xml"

# LOGGING
log() {
    if [ "$1" ]; then
        echo -e "[$(date)] - $1" >> $log_file
    fi
}

# SCRIPT BEGINS
log "Check Initiated"

if [ -f $ip_file ]; then
    old_ip=$(cat $ip_file)
    if [ $ip == $old_ip ]; then
        echo "IP has not changed Old Ip - $old_ip."
        exit 0
    fi
fi

#Update Link
update=$(curl -s "https://dynamicdns.park-your-domain.com/update?host=$host&domain=$domain&password=$pass&ip=$ip")

if [[ $update == *"\"success\":false"* ]]; then
    message="API UPDATE FAILED. DUMPING RESULTS:\n$update"
    log "$message"
    echo -e "$message"
    exit 1
else
    message="IP changed to: $ip"
    echo "$ip" > $ip_file
   echo "$update" > $update_file
    log "$message"
    echo "$message"
fi
#Mood By DarkDroid - DD


Image