找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 4196|回复: 7

IPV6的DDNS脚本怎么写

[复制链接]
发表于 2019-2-28 21:55 | 显示全部楼层 |阅读模式
本帖最后由 hao5764 于 2019-3-1 12:31 编辑

dnspod老是有问题,一直指向,br0接口的,路由IPV6地址 而不是运营商下发的。 设备是K2P。 hiboy的固件。
我已经改了ppp0 问题为什么更新的还一直是br0接口的地址? 目前IP 是我自己改的,可运行脚本后又自动更新成错误的地址。ppp0接口的IP 明明是对的。

# 自行测试哪个代码能获取正确的IP,删除前面的#可生效
arIpAddress () {
# IPv4地址获取
# 获得外网地址
curltest=`which curl`
if [ -z "$curltest" ] || [ ! -s "`which curl`" ] ; then
    #wget --no-check-certificate --quiet --output-document=- "https://www.ipip.net" | grep "IP地址" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
    wget --no-check-certificate --quiet --output-document=- "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
    #wget --no-check-certificate --quiet --output-document=- "ip.6655.com/ip.aspx" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
    #wget --no-check-certificate --quiet --output-document=- "ip.3322.net" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
else
    #curl -L -k -s "https://www.ipip.net" | grep "IP地址" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
    curl -k -s "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
    #curl -k -s ip.6655.com/ip.aspx | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
    #curl -k -s ip.3322.net | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
fi
}
arIpAddress6 () {
# IPv6地址获取
# 因为一般ipv6没有nat ipv6的获得可以本机获得
ifconfig $(nvram get ppp0_ifname_t) | awk '/Global/{print $3}' | awk -F/ '{print $1}'
}
if [ "$IPv6" = "1" ] ; then
arIpAddress=$(arIpAddress6)
else
arIpAddress=$(arIpAddress)
fi


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
我的恩山、我的无线 The best wifi forum is right here.
发表于 2019-2-28 22:04 | 显示全部楼层
我的树莓派用w3m,没有的话可以wget
w3m -no-cookie -dump "https://user:password@nic.ChangeIP.com/nic/update?system=dyndns&hostname=ChangeIP.yours.com"

我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-2-28 22:52 | 显示全部楼层
需要别的脚本,自带的不行

点评

请问有什么其他可以用的地址 ? 脚本更新老更新成br0接口的地址,可我明明改了脚本从ppp0接口获取ip了  详情 回复 发表于 2019-3-1 12:32
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2019-3-1 12:32 | 显示全部楼层
COST 发表于 2019-2-28 22:52
需要别的脚本,自带的不行

请问有什么其他可以用的地址 ?
脚本更新老更新成br0接口的地址,可我明明改了脚本从ppp0接口获取ip了

点评

此脚本可以用,需自己添加域名,token ID密码。 我用H大的固件,只能添加群晖定时任务才能成功。路由器定时任务失败。 #!/bin/sh ################################################# # AnripDdns v5.08 #  详情 回复 发表于 2019-3-1 20:32
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-3-1 14:10 | 显示全部楼层
我用固件自带的脚本能更新wan口下发的ipv6地址啊。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-3-1 20:32 | 显示全部楼层
hao5764 发表于 2019-3-1 12:32
请问有什么其他可以用的地址 ?
脚本更新老更新成br0接口的地址,可我明明改了脚本从ppp0接口获取ip了

此脚本可以用,需自己添加域名,token ID密码。   我用H大的固件,只能添加群晖定时任务才能成功。路由器定时任务失败。
#!/bin/sh

#################################################
# AnripDdns v5.08
# 基于DNSPod用户API实现的动态域名客户端
# 作者: 若海[mail@anrip.com]
# 介绍: http://www.anrip.com/ddnspod
# 时间: 2016-02-24 16:25:00
# Mod: 荒野无灯 http://ihacklog.com  2016-03-16
# ReMod: 寒霜 https://www.frost.net.cn 2018-12-06
#################################################

# 使用Token认证(推荐) 请去 https://www.dnspod.cn/console/user/security 获取
arToken="XXXX,XXXXXXXXXXXXXXXXXXXX"
# 使用邮箱和密码认证
arMail=""
arPass=""

# 获得外网ipv4地址
arIpAdress() {
    local inter=$(nvram get wan0_ipaddr)
    echo $inter
}

# 获得外网ipv6地址
arIpAdress_v6() {
    local hostIP_v6=$(ip addr show ppp0 | grep inet6 | sed 's/\/.*//g' | awk '{print $2}'  | grep 2408)
    while [[ -z $hostIP_v6 ]]
    do
        sleep 60
        hostIP_v6=$(ip addr show ppp0 | grep inet6 | sed 's/\/.*//g' | awk '{print $2}'  | grep 2408)
    done
    echo $hostIP_v6
}

# 读取接口数据
# 参数: 接口类型 Post数据
arApiPost() {
    local agent="AnripDdns/5.07(mail@anrip.com)"
    local inter="https://dnsapi.cn/${1:?'Info.Version'}"
    if [ "x${arToken}" = "x" ]; then # undefine token
        local param="login_email=${arMail}&login_password=${arPass}&format=json&${2}"
    else
        local param="login_token=${arToken}&format=json&${2}"
    fi
    wget --quiet --no-check-certificate --output-document=- --user-agent=$agent --post-data $param $inter
}

# 获得ID与初步数据
getIDs() {
    domainID=$(arApiPost "Domain.Info" "domain=${domain}"|sed 's/.\+{"id":"\([0-9]\+\)".\+/\1/')
    returnDatav4=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${sub_domain}&record_type=A")
    returnDatav6=$(arApiPost "Record.List" "domain_id=${domainID}&sub_domain=${sub_domain}&record_type=AAAA")
}

# 查询域名地址
# 参数: 待查询域名
arNslookup() {
    local lastIP=$(echo $returnDatav4|grep -Eo "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-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[0-4]\d|1\d\d|[1-9]?\d)){3}))|))(%.+)?\s*")
    echo $lastIP_v6
}

# 更新ipv4记录信息
arDdnsUpdate() {
    local recordID recordRS recordCD
    # 获取记录ID
    recordID=$(echo $returnDatav4|sed 's/.\+\[{"id":"\([0-9]\+\)".\+/\1/')
    # 更新记录IP
    recordRS=$(arApiPost "Record.Ddns" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${sub_domain}&record_line=默认")
    recordCD=$(echo $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/')
    # 输出记录IP
    if [ "$recordCD" == "1" ]; then
        echo $recordRS | sed 's/.\+,"value":"\([0-9\.]\+\)".\+/\1/'
        return 0
    fi
    # 输出错误信息
    echo $recordRS | sed 's/.\+,"message":"\([^"]\+\)".\+/\1/'
    return 1
}

# 更新ipv6记录信息
arDdnsUpdate_v6() {
    local hostIP_v6=${1}
    local recordID recordRS recordCD
    recordID=$(echo $returnDatav6|sed 's/.\+\[{"id":"\([0-9]\+\)".\+/\1/')
    # 更新记录IP
    recordRS=$(arApiPost "Record.Modify" "domain_id=${domainID}&record_id=${recordID}&sub_domain=${subdomain}&value=${hostIP_v6}&record_type=AAAA&record_line=默认")
    recordCD=$(echo -E $recordRS | sed 's/.\+{"code":"\([0-9]\+\)".\+/\1/')
    # 输出记录IP
    if [ "$recordCD" == "1" ]; then
        echo "success"
        return 0
    fi
    # 输出错误信息
    echo $recordRS | sed 's/.\+,"code":"\([0-9\.]\+\)".\+/\1/'
    echo $recordRS | sed 's/.\+,"message":"\([^"]\+\)".\+/\1/'
    return 1
}

# 动态检查更新
# 参数: 主域名 子域名
arDdnsCheck() {
    # 全局变量
    domain=$1
    subdomain=$2
    getIDs

    local postRS hostIP lastIP postRS_v6 hostIP_v6 lastIP_v6

    # ipv4
    hostIP=$(arIpAdress)
    echo "hostIP: ${hostIP}"
    lastIP=$(arNslookup)
    echo "lastIP: ${lastIP}"

    if [ "$lastIP" != "$hostIP" ]; then
        arDdnsUpdate
        if [ $? -ne 0 ]; then
            /sbin/ddns_custom_updated 1
        else
            /sbin/ddns_custom_updated 0
        fi
    else
        /sbin/ddns_custom_updated 1
    fi

    # ipv6
    hostIP_v6=$(arIpAdress_v6)
    echo "hostIP_v6: ${hostIP_v6}"
    lastIP_v6=$(arNslookup_v6)
    echo "lastIP_v6: ${lastIP_v6}"

    if [ "$lastIP_v6" != "$hostIP_v6" ]; then
        arDdnsUpdate_v6 ${hostIP_v6}
    fi
}

###################################################
# 检查更新域名
# 指定 domain subdomain
arDdnsCheck "frostfall.cn" ""

点评

老哥 上面一部分字符 变表情了啊。  详情 回复 发表于 2019-3-2 12:46
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2019-3-2 12:46 | 显示全部楼层
COST 发表于 2019-3-1 20:32
此脚本可以用,需自己添加域名,token ID密码。   我用H大的固件,只能添加群晖定时任务才能成功。路由器 ...

老哥 上面一部分字符 变表情了啊。

点评

https://github.com/frostnotfall/DNSPodDdns 搬运自、 实测可用。  详情 回复 发表于 2019-3-2 16:17
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-3-2 16:17 | 显示全部楼层
hao5764 发表于 2019-3-2 12:46
老哥 上面一部分字符 变表情了啊。

https://github.com/frostnotfall/DNSPodDdns
搬运自、   实测可用。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-19 23:15

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表