XY BLOG

XY的BLOG

路由器DDNS脚本 获取本机IP ASUS DDNS & CF DDNS

Published on in Posts
Updated on
Short link: https://b.xyzt07.cn/s/12
Share this post
A ⇄ 文
⚠️ This entry is already over one year old. It may no longer be up to date. Opinions may have changed.
#!/bin/sh
# 获取本机IP
ipv4=$(ifconfig 'ppp0' | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " " )
ipv6=$(ifconfig 'ppp0' | grep "inet6 addr" |head -n 1| cut -f 13 -d " "|cut -d'/' -f1)
arg="${ipv4}-${ipv6}"


IP=`ping [your ddns address] -c 1 |awk 'NR==2 {print $4}' |awk -F ':' '{print $1}'`
echo $IP
echo $ipv4

# 华硕DDNS
if [ $IP == $ipv4 ]
then

echo "asus ddns yes"

else

curl --request GET "https://ns1.asuscomm.cn/ddns/update.jsp?hostname=[your ddns address]&myip=${ipv4}&myipv6=${ipv6}&model=[RT-AC68U]&fw_ver=3.0.0.4.386.12_0" \
 -H 'Authorization: Basic [your auth code]' \
 -H 'User-Agent: inadyn/2.10.0 https://github.com/troglobit/inadyn/issues'
echo "update asus ddns"

fi

# CFDDNS
CFIP=`ping [your ddns address] -c 1 |awk 'NR==2 {print $4}' |awk -F ':' '{print $1}'`

if [ $CFIP == $ipv4 ]
then

echo "cf ddns yes"

else

data='{
  "content": "'${ipv4}'",
  "name": "[your ddns address]",
  "proxied": false,
  "type": "A",
  "comment": "Domain verification record",
  "ttl": 120
}'

curl --request PUT \
  --url https://api.cloudflare.com/client/v4/zones/[your cf zone]/dns_records/[your cf dns record] \
  --header 'Content-Type: application/json' \
  --header 'X-Auth-Email: ' \
  -H "Authorization: Bearer [your auth key]" \
  --data "${data}"
echo "update cf ddns"
fi
echo $arg