Created
October 14, 2022 07:30
-
-
Save fahadysf/835982f015a7b6264b9acff7c8583e50 to your computer and use it in GitHub Desktop.
Bash script to update NameCheap DDNS
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/sh | |
dnsserver="freedns2.registrar-servers.com" | |
host="host" | |
domain_name="your.domain" | |
ddns_password="YOUR-DDNS-PASSWORD-HERE" | |
dnsrecord=$host.$domain_name | |
# Get the current external IP address | |
current_ip=`curl -s -X GET https://checkip.amazonaws.com` | |
datestr=`date` | |
## NameChaep FreeDNS Dynamic Update URL | |
## keep these private | |
UPDATE_URL="https://dynamicdns.park-your-domain.com/update?host=$host&domain=$domain_name&password=$ddns_password&ip=$current_ip" | |
echo "[$datestr] Current IP is $current_ip" | |
dnsresult="[$datestr] `host $dnsrecord $dnsserver | grep 'has address'`" | |
if echo $dnsresult | grep "$current_ip"; then | |
echo "[$datestr] $dnsrecord is currently set to $current_ip; no changes needed" | |
exit 0 | |
fi | |
# if here, the dns record needs updating | |
result=`curl -s -X GET $UPDATE_URL` | |
echo "[$datestr] Update Result: \n$result" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment