#!/usr/bin/env nix-shell #! nix-shell -i bash -p bash curl jq dig # Shell script to update namecheap.com dynamic dns # for a domain to your external IP address # namecheap hostnames=(cloud @) domain=rotehaare.art password=60d672be5d9d4828a0f96264babe0ac1 ip=$(curl -s ipecho.net/plain) for hostname in "${hostnames[@]}"; do curl "https://dynamicdns.park-your-domain.com/update?host=$hostname&domain=$domain&password=$password&ip=$ip" done # cloudflare zone_id=833996ed25eb09f1a50606e0457790e4 record=servidos.lat record_id=6b117173e53a7511ba36ceb9637ede63 cloudflare_token=VdKosfThQmOcuywLOUq9DY4-df9EmbHrDWyf_vUb # get record_id # curl -s -X GET "https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records?type=A&name=${record}" \ # -H "Authorization: Bearer ${cloudflare_token}" \ # -H "Content-Type: application/json" | jq -r '{"result"}[] | .[0] | .id' curr_ip=$(curl -s -X GET https://checkip.amazonaws.com) curr_reg=$(dig ${record} +short @1.1.1.1) if echo "${curr_reg}" | grep "${curr_ip}"; then echo "$(date --rfc-3339=seconds) - OK - Current record matches current IP (${curr_ip})" else curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/${zone_id}/dns_records/${record_id}" \ -H "Authorization: Bearer ${cloudflare_token}" \ -H "Content-Type: application/json" \ --data "{\"type\":\"A\",\"name\":\"${record}\",\"content\":\"$curr_ip\",\"ttl\":1,\"proxied\":false}" >/dev/null echo "$(date --rfc-3339=seconds) - NOK - Record Updated to $curr_ip from ${curr_reg}" fi