Skip to content

Instantly share code, notes, and snippets.

@sunnyyoung
Created August 5, 2022 17:11
Show Gist options
  • Save sunnyyoung/e11315879b1a1a23e0cc6797394b1b92 to your computer and use it in GitHub Desktop.
Save sunnyyoung/e11315879b1a1a23e0cc6797394b1b92 to your computer and use it in GitHub Desktop.
Synology namecheap DDNS provider script
#!/bin/bash
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment