萝卜大侠 发表于 2023-5-22 15:01:07

适用于dynv6的DDNS脚本

折腾了一下第三方的IPV6 ddns,脚本如下,如果有人喜欢后续给大家做个ipk
#!/bin/sh -e
hostname=$1
device=$2
file=$HOME/.dynv6.addr6
[ -e $file ] && old=`cat $file`

if [ -z "$hostname" -o -z "$token" ]; then
echo "Usage: token=<your-authentication-token> $0 your-name.dynv6.net "
exit 1
fi

if [ -z "$netmask" ]; then
netmask=128
fi

if [ -n "$device" ]; then
device="dev $device"
fi
address=$(ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \(\+\).*/\1/p' | head -n 1)

if [ -e /usr/bin/curl ]; then
bin="curl -fsS"
elif [ -e /usr/bin/wget ]; then
bin="wget -O-"
else
echo "neither curl nor wget found"
exit 1
fi

if [ -z "$address" ]; then
echo "no IPv6 address found"
exit 1
fi

# address with netmask
current=$address/$netmask

if [ "$old" = "$current" ]; then
echo "IPv6 address unchanged"
exit
fi

# send addresses to dynv6
$bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$token"
$bin "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$token"

# save current address
echo $current > $file使用方法
token=oUuMMyaHUgsboqGEijvf_L-eiFSyRM ./dynv6.sh luochongjun.dynv6.net usb0
token请从自己的账户下获取,luochongjun.dynv6.net 是我的域名 usb0是我这里具备IPV6公网地址的接口,请自己根据实际情况替换
以上命令每次执行更新一次IP,可以自己写个定时任务来自动更新
可以使用nslookup命令来检查DDNS是否生效



junexx4437492 发表于 2023-7-15 20:55:35

确实需要,第三方的DDNS总是有问题
页: [1]
查看完整版本: 适用于dynv6的DDNS脚本