Skip to content

Instantly share code, notes, and snippets.

@jroehl
Last active April 26, 2019 14:34
Show Gist options
  • Save jroehl/25dcd6a35d5cf7809d3274439a1e6783 to your computer and use it in GitHub Desktop.
Save jroehl/25dcd6a35d5cf7809d3274439a1e6783 to your computer and use it in GitHub Desktop.

Bash script to update the ddns entry of a namecheap domain

Needs yq (pip install yq) and dig to be installed

Usage

curl -s https://gist.githubusercontent.com/jroehl/25dcd6a35d5cf7809d3274439a1e6783/raw/update-ddns.sh | bash -s "host" "domain" "password"

#!/usr/bin/env bash
HOST="$1"
DOMAIN="$2"
PASSWORD="$3"
if [ "$HOST" == "@" ]; then
SET_IP=$(dig +short ${DOMAIN})
else
SET_IP=$(dig +short ${HOST}.${DOMAIN})
fi
CURRENT_IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
echo "IP of a-record \"${HOST}.${DOMAIN}\" = \"${SET_IP}\" / current ip \"${CURRENT_IP}\""
if [ "$CURRENT_IP" != "$SET_IP" ]; then
RES=`curl -s -X GET "https://dynamicdns.park-your-domain.com/update?host=${HOST}&domain=${DOMAIN}&password=${PASSWORD}&ip=${CURRENT_IP}"`
if command -v xq >/dev/null 2>&1; then
echo $RES | xq '.'
else
echo $RES
fi
else
echo "DDNS entry already up to date (${CURRENT_IP})"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment