Sample script for updating current IP in dd-wrt, open-wrt and other linux based OS

Sample Script (Cloudflare)

#!/bin/bash
GET_LATEST_IP="curl ifconfig.co"
LATEST_IP=`$GET_LATEST_IP`
#echo $LATEST_IP
CLOUDFLARE="curl -X PUT \"https://api.cloudflare.com/client/v4/zones/ZONE-ID/dns_records/DNS-RECORD-ID\" -H \"X-Auth-Email: AUTH-EMAIL-ADDRESS\" -H \"X-Auth-Key: AUTH-KEY\" -H \"Content-Type: application/json\" --data '{\"type\":\"A\",\"name\":\"DOMAIN-NAME\",\"content\":\"$LATEST_IP\",\"ttl\":1,\"proxied\":false}'"
RESPONSE=`$CLOUDFLARE`
#echo $RESPONSE

Sample ID format:
ZONE-ID: xxx517f1e30dbxxxc1f8be73xxx6ab2a
DNS-RECORD-ID: xxxd3db8axxx026xxx95876a77703fe1
AUTH-EMAIL-ADDRESS: name@email.com
AUTH-KEY: xxxa30184b74axxx8b3e67xxx5d426fe7xx16
DOMAIN-NAME: xxx.yyy.com

Get Latest IP

curl ifconfig.co > /root/ip

Get ZoneID

curl -X GET "https://api.cloudflare.com/client/v4/zones" \
-H "X-Auth-Email: AUTH-EMAIL-ADDRESS" \
-H "X-Auth-Key: AUTH-KEY" \
-H "Content-Type: application/json"

List DNS Records

curl -X GET "https://api.cloudflare.com/client/v4/zones/ZONE-ID/dns_records?" \
-H "X-Auth-Email: AUTH-EMAIL-ADDRESS" \
-H "X-Auth-Key: AUTH-KEY" \
-H "Content-Type: application/json"

Update DNS record

curl -X PUT "https://api.cloudflare.com/client/v4/zones/ZONE-ID/dns_records/DNS-RECORD-ID" \
-H "X-Auth-Email: AUTH-EMAIL-ADDRESS" \
-H "X-Auth-Key: AUTH-KEY" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":DOMAIN-NAME","content":IP-ADDRESS","ttl":1,"proxied":false}'

Leave a comment

What do you think?