Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Created August 26, 2021 13:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ttscoff/fab7137c71d951d36b166622a4d5800d to your computer and use it in GitHub Desktop.
Save ttscoff/fab7137c71d951d36b166622a4d5800d to your computer and use it in GitHub Desktop.
Namecheap DDNS for Synology
#!/bin/bash
## Namecheap DDNS updater for Synology
## Brett Terpstra <https://brettterpstra.com>
PASSWORD="$2"
DOMAIN="$3"
IP="$4"
PARTS=$(echo $DOMAIN | awk 'BEGIN{FS="."} {print NF?NF-1:0}')
# If $DOMAIN has two parts (domain + tld), use wildcard for host
if [[ $PARTS == 1 ]]; then
HOST='@'
DOMAIN=$DOMAIN
# If $DOMAIN has a subdomain, separate for HOST and DOMAIN variables
elif [[ $PARTS == 2 ]]; then
HOST=${DOMAIN%%.*}
DOMAIN=${DOMAIN#*.}
fi
RES=$(curl -s "https://dynamicdns.park-your-domain.com/update?host=$HOST&domain=$DOMAIN&password=$PASSWORD&ip=$IP")
ERR=$(echo $RES | sed -n "s/.*<ErrCount>\(.*\)<\/ErrCount>.*/\1/p")
if [[ $ERR -gt 0 ]]; then
echo "badauth"
else
echo "good"
fi
@gwythan
Copy link

gwythan commented Aug 7, 2022

Thank you for this script! Are you able to improve the parsing logic so that it accepts TLDs with multiple parts? For example:
domain.co.uk
domain.com.au
domain.co.nz

Best regards

@ttscoff
Copy link
Author

ttscoff commented Aug 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment