Created
April 16, 2025 11:18
-
-
Save sphinxid/9ac5d696781d321b920e1db6de250ddc to your computer and use it in GitHub Desktop.
Simple DDNS updater for noip.com - Checks your real IP first before sending update.
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/bash | |
# Configuration variables | |
USERNAME="your_username" | |
PASSWORD="your_password" | |
HOSTNAME="mytest.example.com" | |
# Path to required binaries | |
CURL="/usr/bin/curl" | |
DIG="/usr/bin/dig" | |
# Get current external IP address from kodelatte.com | |
CURRENT_IP=$($CURL -s https://kodelatte.com/) | |
# Check if we got a valid IP address | |
if [[ ! $CURRENT_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Error: Could not retrieve a valid IP address from kodelatte.com" | |
exit 1 | |
fi | |
echo "Current external IP: $CURRENT_IP" | |
# Get the current DNS record for the hostname | |
DNS_IP=$($DIG +short "$HOSTNAME" A | grep -v "\.$" | head -n 1) | |
if [ -z "$DNS_IP" ]; then | |
echo "No DNS record found for $HOSTNAME or dig command failed" | |
echo "Proceeding with update..." | |
elif [ "$DNS_IP" == "$CURRENT_IP" ]; then | |
echo "DNS record is already up to date ($DNS_IP). No update needed." | |
exit 0 | |
else | |
echo "DNS record ($DNS_IP) differs from current IP ($CURRENT_IP). Update needed." | |
fi | |
# Construct the update URL | |
UPDATE_URL="http://$USERNAME:[email protected]/nic/update?hostname=$HOSTNAME&myip=$CURRENT_IP" | |
# Send the update request | |
echo "Sending DNS update request..." | |
RESPONSE=$($CURL -s "$UPDATE_URL") | |
# Display the response | |
echo "Response: $RESPONSE" | |
# Check response for common status codes | |
if [[ "$RESPONSE" == "good"* ]]; then | |
echo "Update successful! IP address has been updated." | |
elif [[ "$RESPONSE" == "nochg"* ]]; then | |
echo "No change needed. Your IP address is already up to date." | |
elif [[ "$RESPONSE" == "nohost" ]]; then | |
echo "Error: Hostname does not exist." | |
elif [[ "$RESPONSE" == "badauth" ]]; then | |
echo "Error: Invalid username or password." | |
elif [[ "$RESPONSE" == "abuse" ]]; then | |
echo "Error: Abuse detected. Your account has been blocked." | |
else | |
echo "Unrecognized response. Please check the documentation for more information." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment