menu LittleJake's Blog
color_lens
avatar
Jake Liu
Never Settle
creative commons by-nc-sa
hit
Category
keyboard_arrow_down

© 2024 LittleJake's Blog.

萌ICP备20223020号

通过cloudflare API实现个人域名免费ddns效果IPV6版

cloudflare
首先需要一个linux的路由器(openwrt等)

获取一个Cloudflare和一个域名

Cloudflare的DNS ID可以通过路由器执行获取:

curl -k -X GET "https://api.cloudflare.com/client/v4/zones/NULL/dns_records" \
-H "X-Auth-Email:NULL" \
-H "X-Auth-Key:NULL" \
-H "Content-Type: application/json"

将以下代码保存为shell文件

#!/bin/sh
CF_API_KEY=API
CF_ZONE_ID=ZONEID
CF_DNS_ID=DNSID
NET_DEV=device
EMAIL=Email
TEMP_FILE_PATH=/tmp/cloudflare-ddns/
DNS_RECORD=domain

mkdir -p NULL
curl -k -X GET "https://api.cloudflare.com/client/v4/zones/NULL/dns_records/NULL" \
-H "X-Auth-Email:NULL" \
-H "X-Auth-Key:NULL" \
-H "Content-Type: application/json" |awk -F '"' '{print $18}'>NULL/current_resolving.txt
ifconfig NULL | awk -F'[ /]+' '/inet6 /{print $4}'|head -n 1 >NULL/current_ip.txt
if [ "$(cat NULL/current_ip.txt)" == "$(cat NULL/current_resolving.txt)" ];
then
exit 1
else
CURRENT_IP="$(cat NULL/current_ip.txt)"
curl -k -X PUT "https://api.cloudflare.com/client/v4/zones/NULL/dns_records/NULL" \
-H "X-Auth-Email:NULL" \
-H "X-Auth-Key:NULL" \
-H "Content-Type: application/json" \
--data '{"type":"AAAA","name":"'$DNS_RECORD'","content":"'$CURRENT_IP'","ttl":1,"proxied":false}'
fi

设置crontab进行每间隔时间执行

Buy me a beer
Jake Liu
Never Settle

Title: 通过cloudflare API实现个人域名免费ddns效果IPV6版

Author: Jake Liu

Origin:

Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) For any re-post you must give appropriate credit.

文章遵循CC许可 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 转载请注明出处

Tag:cloudflare, OpenWrt, Linux

评论区

Add a new comment.

Theme