Skip to content

Instantly share code, notes, and snippets.

@the0demiurge
Last active November 17, 2020 04:01
Show Gist options
  • Save the0demiurge/6b42e5f46ef7a402f580474b419fe871 to your computer and use it in GitHub Desktop.
Save the0demiurge/6b42e5f46ef7a402f580474b419fe871 to your computer and use it in GitHub Desktop.
Simple Namecheap Dynamic DNS client
#!/bin/sh
set -eu
FETCH="curl -sL"
# or for curl:
# FETCH="fetch -qo -"
# $1: Your domain
# $2: Subdomain A record to update. Use @ for TLD.
# $3: The password given to you by Namecheap's web interface
#
# Rerun this script every 5 minutes. Crontab entry:
# */5 * * * * namecheap-ddns bla.com @ asdjfasfasdfasdf
#
# Consider enabling your crond's time jitter if you update
# multiple domains to not make too many requests at once to
# Namecheap's service.
domain=pythonic.life
host=laptop
password="do not tell others"
ip=$(${FETCH} "https://dynamicdns.park-your-domain.com/getip")
out=$(${FETCH} "https://dynamicdns.park-your-domain.com/update?host=${host}&domain=${domain}&password=${password}&ip=${ip}")
grep -q "<ErrCount>0</ErrCount>" <<EOF && exit 0
${out}
EOF
cat <<EOF
${out}
EOF
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment