Created
February 2, 2020 01:40
-
-
Save deoxykev/f9b0f2eb256c69e65333c942aa8afbbf to your computer and use it in GitHub Desktop.
DDNS client for namecheap with systemd init script
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 | |
# update namecheap ddns from unraid | |
# 2020-01-06 | |
# systemd init script: | |
# [Unit] | |
# Description=Updates internal DDNS for meowth.kanto.blue | |
# After=network.target | |
# | |
# [Service] | |
# Restart=always | |
# RestartSec=5 | |
# ExecStart=/path/to/update-ddns.sh | |
# | |
# [Install] | |
# WantedBy=default.target | |
HOSTNAME=<subdomain> | |
DOMAIN=<yourdomain.com> | |
PASSWORD=<namecheapDDNSkey> | |
INTERFACE='enp2s0' | |
while true; do | |
touch "${HOME}/.ddns" | |
LASTIP="$(cat "${HOME}/.ddns")" | |
IP="$(ip addr show $INTERFACE | grep -Po 'inet \K[\d.]+')" | |
if [[ "$LASTIP" != "$IP" ]]; then | |
if curl -s "https://dynamicdns.park-your-domain.com/update?host=$HOSTNAME&domain=$DOMAIN&password=$PASSWORD&ip=$IP" | grep '<ErrCount>0</ErrCount>'; then | |
echo "$IP" > "${HOME}/.ddns" | |
echo "[+] DDNS: $IP" | |
else | |
echo "[-] Failed to update DDNS" | |
fi | |
fi | |
sleep 5 | |
done | |
exit 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment