Last active
April 19, 2023 23:26
-
-
Save jangins101/9f78ab7fb8e5ff2c60bf to your computer and use it in GitHub Desktop.
Bash script for updating Namecheap DDNS IP address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Variables | |
LAST_IP_FILE=/tmp/lastip.txt | |
LOGFILE=/var/log/namecheap.log | |
TIME="`date +%Y-%m-%d:%H:%M`" | |
HOST=@ | |
DOMAIN=example.com | |
PASSWORD=0123456789abcdef0123456789abcdef | |
echo "TIME: $TIME" | |
# Grab last IP | |
LAST_IP=`cat $LAST_IP_FILE` | |
echo "LAST IP: $LAST_IP" | |
# Get current IP | |
IP="`wget --no-check-certificate -qO - https://dynamicdns.park-your-domain.com/getip`" | |
echo "CURRENT IP: $IP" | |
# Check if IP has changed | |
if [ "$IP" = "$LAST_IP" ]; then | |
echo "IP has not changed" | |
echo "Exiting" | |
exit 1 | |
fi | |
# Update Namecheap DDNS | |
URL="wget --no-check-certificate -qO - https://dynamicdns.park-your-domain.com/update?host=$HOST&domain=$DOMAIN&password=$PASSWORD&ip=$IP" | |
RESPONSE=$($URL) | |
echo "Response:" | |
echo $RESPONSE | |
# Save the current IP as the last IP | |
echo "$IP" >> $LAST_IP_FILE | |
# Log the time and IP | |
echo "$TIME - $IP" >> $LOGFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment