让网维变得简单,快速,准确。拒绝浪费时间,解放出更多的时间陪陪家人。 注册 | 登陆

新建ROS的DNSPOD脚本更新项目(2020/12/21更新)

 
本项目完全免费公开脚本源码。

ROS的DNSPOD脚本更新:
1.可直接对接DNSPOD官方服务器进行更新。(无需借助任何第三方服务器,再也不用担心安全问题了!)
2.一个脚本可以支持IPV4和IPV6的DDNS更新,填补ROS目前IPV6的DDNS解决方案的空白。
3.检测子域名不存在时自动创建
4.支持域名使用V4+V6双栈,2个IP共用一个域名
5.增加日志记录流程
6.增加域名ID缓存功能,减少API交互次数

使用条件:
1.将ROS系统版本升级到6.45.6或更高
安装并启用IPV6组件
2.没有IPV6的环境,无需填写V6的域名。(mydomains4代表V4的域名,mydomains6代表V6的域名
可以是同一个域名开启双栈。
3.子域名请尽量全部大于3位,如果子域名列表里同时存在1.x.com和11.x.com记录时会出现误判
4.
使用V4V6同时更新的域名,顶级域名必须一致,否则会因为缓存域名ID导致后续更新失败
5.不要多个拨号接口引用这同一个PPP模板
6.由于目前V6并没有统一标准,环境不一定兼容,如发现异常可以与我联系排查。


更新时间:2020/12/21
更新内容:取消使用
Domain.List相关API。不再调用出现过故障的keyword函数。


PHP代码
  1. ###程序执行完需要较长时间,请耐心等待,不要反复执行,建议放在PPP模板里ON-UP使用###  
  2. ###注意事项:子域名请尽量全部大于3位,如果子域名列表里同时存在1.x.com和11.x.com记录时会出现误判###  
  3. ###注意事项:使用V4V6同时更新的域名,顶级域名必须一致,否则会因为缓存域名ID导致后续更新失败###  
  4. ###定义必须变量#####  
  5. ###定义DNSPOD的TOKEN###  
  6. :local mytoken "xxxxx,xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  
  7. ###定义自己的需更新域名(不需要更新的IP类型留空即可)###  
  8. :global mydomains4 "abc4.123.com"  
  9. :global mydomains6 "abc6.123.com"  
  10. ###定义自己的需更新的拨号接口###  
  11. :global myint "pppoe-out1"  
  12. ###以下内容无需修改###  
  13. ###预判断域名是否为双栈###  
  14. :global v4putex ""  
  15. :global v6putex ""  
  16. :if ($mydomains4 = $mydomains6do={:log error "检测到当前更新域名使用双栈。";:global v4putex "&offset=0&length=1";:global v6putex "&offset=1&length=1";}  
  17. :if ([:len $mydomains4] >0) do={  
  18. ###开始IPV4获取工作,可自行按需调整###  
  19. :global mydomain41 [:pick $mydomains4 ([:find $mydomains4 "."] +1) [:len $mydomains4]]  
  20. :global mydomain42 [:pick $mydomains4 0 [:find $mydomains4 "."]]  
  21. :global myipv4 [/ip address get [find interface=$myint] address]  
  22. :set myipv4 [:pick $myipv4 0 [:find $myipv4 "/"]]  
  23. ###开始DNSPOD处理IPV4工作,以下请勿修改###  
  24. :log error "DNSPOD脚本执行IPV4更新开始"  
  25. :do [/tool fetch url="https://dnsapi.cn/Record.List" http-data="login_token=$mytoken&format=json&domain=$mydomain41&sub_domain=$mydomain42&$v4putex"]  
  26. :delay 5s  
  27. :global reprec [/file get [find name="Record.List"] contents]  
  28. :if ([:len [:find $reprec "u7a7a"]] >0) do={  
  29. /file remove [find name="Record.List"]  
  30. :log error "DNSPOD因为没有对应子域名,尝试自己NEW一个。"  
  31. :global myipv4  
  32. :do [/tool fetch url="https://dnsapi.cn/Record.Create" http-data="login_token=$mytoken&format=json&domain=$mydomain41&sub_domain=$mydomain42&value=$myipv4&record_type=A&record_line=%e9%bb%98%e8%ae%a4" keep-result=no]  
  33. :delay 5s  
  34. :do [/tool fetch url="https://dnsapi.cn/Record.List" http-data="login_token=$mytoken&format=json&domain=$mydomain41&sub_domain=$mydomain42"]  
  35. :delay 5s  
  36. :global reprec [/file get [find name="Record.List"] contents]  
  37. }  
  38. :if ([:len [:find $reprec "u6210"]] >0) do={  
  39. :global dnspodf [/file get [find name="Record.List"] contents]  
  40. :global fdend [:find $dnspodf ("\"".$mydomain42."\"")]  
  41. :global fdinfo [:pick $dnspodf 0 $fdend]  
  42. :while ([:len [:find $fdinfo "{"]] > 0) do={  
  43. :global fdinfo [:pick $fdinfo ([:find $fdinfo "{"] +1) [:len $fdinfo]]}  
  44. :global fdinfo [:pick $fdinfo 6 [:len $fdinfo]]  
  45. :global fdinfo [:pick $fdinfo 0 [:find $fdinfo "\","]]  
  46. :global recordid $fdinfo  
  47. /file remove [find name="Record.List"]  
  48. :global myipv4  
  49. :if ([:len [:find $dnspodf $myipv4]] >0) do={  
  50. :log error ("DNSPOD放弃更新,IPV4没有变化。")  
  51. else={  
  52. :do [/tool fetch url="https://dnsapi.cn/Record.Modify" http-data="login_token=$mytoken&format=json&domain=$mydomain41&record_id=$recordid&sub_domain=$mydomain42&value=$myipv4&record_type=A&record_line=%e9%bb%98%e8%ae%a4"]  
  53. :delay 5s  
  54. :global reprec [/file get [find name="Record.Modify"] contents]  
  55. /file remove [find name="Record.Modify"]  
  56. :if ([:len [:find $reprec "u6210"]] >0) do={  
  57. :log error ("DNSPOD更新IPV4成功。当前IPV4为:".myipv4)  
  58. else={  
  59. :log error "DNSPOD更新IPV4失败"  
  60. }}}  
  61. :log error "DNSPOD执行脚本IPV4更新完毕"}  
  62. :if ([:len $mydomains6] >0) do={  
  63. ###开始IPV6获取工作,可自行按需调整###  
  64. :global mydomain61 [:pick $mydomains6 ([:find $mydomains6 "."] +1) [:len $mydomains6]]  
  65. :global mydomain62 [:pick $mydomains6 0 [:find $mydomains6 "."]]  
  66. :global myipv6 [/ip address get [find interface=$myint] address]  
  67. :set myipv6 [:pick $myipv6 0 [:find $myipv6 "/"]]  
  68. ###有的朋友这里V6使用release会有问题,可更换为renew尝试,和运营商有关###  
  69. /ipv6 dhcp-client release [find interface=$myint]  
  70. :delay 3s  
  71. :global myipv6 [/ipv6 dhcp-client get [find interface=$myint status=bound] prefix]  
  72. :set myipv6 [:pick $myipv6 0 [:find $myipv6 "/"]]  
  73. ###开始DNSPOD处理IPV6工作,以下请勿修改###  
  74. :log error "DNSPOD脚本执行IPV6更新开始"  
  75. :do [/tool fetch url="https://dnsapi.cn/Record.List" http-data="login_token=$mytoken&format=json&domain=$mydomain61&sub_domain=$mydomain62&$v6putex"]  
  76. :delay 5s  
  77. :global reprec [/file get [find name="Record.List"] contents]  
  78. :if ([:len [:find $reprec "u7a7a"]] >0) do={  
  79. /file remove [find name="Record.List"]  
  80. :log error "DNSPOD因为没有对应子域名,尝试自己NEW一个。"  
  81. :global myipv6  
  82. :do [/tool fetch url="https://dnsapi.cn/Record.Create" http-data="login_token=$mytoken&format=json&domain=$mydomain61&sub_domain=$mydomain62&value=$myipv6&record_type=AAAA&record_line=%e9%bb%98%e8%ae%a4" keep-result=no]  
  83. :delay 5s  
  84. :do [/tool fetch url="https://dnsapi.cn/Record.List" http-data="login_token=$mytoken&format=json&domain=$mydomain61&sub_domain=$mydomain62"]  
  85. :delay 5s  
  86. :global reprec [/file get [find name="Record.List"] contents]}  
  87. :if ([:len [:find $reprec "u6210"]] >0) do={  
  88. :global dnspodf [/file get [find name="Record.List"] contents]  
  89. :global fdend [:find $dnspodf ("\"".$mydomain62."\"")]  
  90. :global fdinfo [:pick $dnspodf 0 $fdend]  
  91. :while ([:len [:find $fdinfo "{"]] > 0) do={  
  92. :global fdinfo [:pick $fdinfo ([:find $fdinfo "{"] +1) [:len $fdinfo]]}  
  93. :global fdinfo [:pick $fdinfo 6 [:len $fdinfo]]  
  94. :global fdinfo [:pick $fdinfo 0 [:find $fdinfo "\","]]  
  95. :global recordid $fdinfo  
  96. /file remove [find name="Record.List"]  
  97. :global myipv6  
  98. :if ([:len [:find $dnspodf $myipv6]] >0) do={  
  99. :log error ("DNSPOD放弃更新,IPV6没有变化。")  
  100. else={  
  101. :do [/tool fetch url="https://dnsapi.cn/Record.Modify" http-data="login_token=$mytoken&format=json&domain=$mydomain61&record_id=$recordid&sub_domain=$mydomain62&value=$myipv6&record_type=AAAA&record_line=%e9%bb%98%e8%ae%a4"]  
  102. :delay 5s  
  103. :global reprec [/file get [find name="Record.Modify"] contents]  
  104. /file remove [find name="Record.Modify"]  
  105. :if ([:len [:find $reprec "u6210"]] >0) do={  
  106. :log error ("DNSPOD更新IPV6成功。当前IPV6为:".myipv6)  
  107. else={  
  108. :log error "DNSPOD更新IPV6失败"  
  109. }}}  
  110. :log error "DNSPOD执行脚本IPV6更新完毕"}    

 

附件: ros对接dnspod直通版v4.txt (7.62 K, 下载次数:1315)

附件: ros对接dnspod直通版v5.txt (6.15 K, 下载次数:1138)

Tags: dns, 解析, ddns, ipv6, 动态

« 上一篇 | 下一篇 »

 

24条记录访客评论

引用 寒心浪子 说过的话:
目前又不能更新了

刚测试了工作正常。

Post by 熊茂祥 on 2022, May 29, 9:43 AM 引用此文发表评论 #1

目前又不能更新了

Post by 寒心浪子 on 2022, May 28, 11:38 PM 引用此文发表评论 #2

引用 charwin 说过的话:
:do [/tool fetch url=\"https://dnsapi.cn/Record.Info\" http-data=\"login_token=$myToken&format=json&domain_id=$domainId&record_id=$recordId\"]
:delay 5s
:local dnspodf [/file get [find name=\"Record.Info\"] contents]
:local num1 [:find $dnspodf value]
:local num2 [:find $dnspodf weight]
:local fdend [:pick $dnspodf ($num1 + 8) (num2 - 3)]
域名记录查IP 这样 是不是 更快呢

感谢提供参考,但是目前没有更新计划哦。

Post by 熊茂祥 on 2021, April 19, 11:16 PM 引用此文发表评论 #3

:do [/tool fetch url=\"https://dnsapi.cn/Record.Info\" http-data=\"login_token=$myToken&format=json&domain_id=$domainId&record_id=$recordId\"]
:delay 5s
:local dnspodf [/file get [find name=\"Record.Info\"] contents]
:local num1 [:find $dnspodf value]
:local num2 [:find $dnspodf weight]
:local fdend [:pick $dnspodf ($num1 + 8) (num2 - 3)]

域名记录查IP 这样 是不是 更快呢

Post by charwin on 2021, April 4, 6:36 PM 引用此文发表评论 #4

引用 等待 说过的话:
问题不知道为啥,这脚本填写了我自己对应的信息后直接粘贴在PPP-ON模板里在对应外网重拨时没有牵引触发执行,log中也没看到提示,所以我才觉得是脚本问题还是版本问题,6.48的X86和CCR还有RB版本都试过,我专门建立了一个模版,并且让对应的外网拨号使用此模版拨号,昨晚给你留言之前我本身的命令就是sys scr run dsnpod  非常感谢大猫的回复

看看日志情况呢,联系微信x9939781联系我发日志截图排查

Post by 熊茂祥 on 2021, January 21, 10:24 PM 引用此文发表评论 #5

问题不知道为啥,这脚本填写了我自己对应的信息后直接粘贴在PPP-ON模板里在对应外网重拨时没有牵引触发执行,log中也没看到提示,所以我才觉得是脚本问题还是版本问题,6.48的X86和CCR还有RB版本都试过,我专门建立了一个模版,并且让对应的外网拨号使用此模版拨号,昨晚给你留言之前我本身的命令就是sys scr run dsnpod  非常感谢大猫的回复

Post by 等待 on 2021, January 21, 3:47 AM 引用此文发表评论 #6

引用 等待 说过的话:
这个脚本直接放在ppp模版中是无效的,把这个脚本放在sys-script中,在ppp的模版中执行sys scr run number=0  也不行,是不是可以添加一个自动检测对应域名对应线路IP对照,IP变动就自动运行sys scr run number=0  ,ip未变动则不运行sys scr run number=0  ???

脚本直接粘贴在PPP-ON模板里,让拨号引用这个模板即可。引用外部脚本你的语法错误,sys scr run xxx即可

Post by 熊茂祥 on 2021, January 20, 10:07 AM 引用此文发表评论 #7

这个脚本直接放在ppp模版中是无效的,把这个脚本放在sys-script中,在ppp的模版中执行sys scr run number=0  也不行,是不是可以添加一个自动检测对应域名对应线路IP对照,IP变动就自动运行sys scr run number=0  ,ip未变动则不运行sys scr run number=0  ???

Post by 等待 on 2021, January 20, 4:11 AM 引用此文发表评论 #8

引用 rosuser 说过的话:
此脚本近期出现问题,无法更新。
后端dnspod上删除aaa主机后发现无法增加。老版v4正常。
之前一直工作正常。近期重启后无法使用。单v4的没问题。但是缺少接口定义。

已经发现获取域名列表的keyword函数执行不正常,已经提交工单转交腾讯处理。

Post by 熊茂祥 on 2020, December 21, 6:41 PM 引用此文发表评论 #9

dnspod api 又更新了,代码已失效,麻烦更新下,谢谢了!!!

Post by gengjingfeng on 2020, December 20, 6:15 PM 引用此文发表评论 #10

重启后一直再重复     “未获取到缓存的域名ID,执行域名ID获取步骤”无法修改dns。

Post by liulikang on 2020, December 16, 8:27 PM 引用此文发表评论 #11

此脚本近期出现问题,无法更新。
后端dnspod上删除aaa主机后发现无法增加。老版v4正常。
之前一直工作正常。近期重启后无法使用。单v4的没问题。但是缺少接口定义。

Post by rosuser on 2020, December 16, 7:11 PM 引用此文发表评论 #12

[quote=熊茂祥][/quote]最近又正常了,大约有一周时间是不能正常使用的,我一直保持最新版本的目前6.47.3,谢谢

Post by 寒心浪子 on 2020, September 14, 6:53 PM 引用此文发表评论 #13

引用 寒心浪子 说过的话:
貌似出问题了,又无法更新了,在储存器上生成了Record.list文件,打开内容为“{"status":{"code":"6","message":"\u57df\u540d\u7f16\u53f7\u4e0d\u6b63\u786e","created_at":"2020-08-30 22:44:28"}}”,经过转换结果为域名编号不正确。

我这检测正常,参考一下使用条件是否满足。
使用条件:
1.将ROS系统版本升级到6.45.6或更高,安装并启用IPV6组件。
2.没有IPV6的环境,无需填写V6的域名。(mydomains4代表V4的域名,mydomains6代表V6的域名。可以是同一个域名开启双栈。)
3.子域名请尽量全部大于3位,如果子域名列表里同时存在1.x.com和11.x.com记录时会出现误判
4.使用V4V6同时更新的域名,顶级域名必须一致,否则会因为缓存域名ID导致后续更新失败
5.不要多个拨号接口引用这同一个PPP模板

如果依然不正常建议使用
https://ros6.com/?action=show&id=203

Post by 熊茂祥 on 2020, September 8, 11:27 AM 引用此文发表评论 #14

貌似出问题了,又无法更新了,在储存器上生成了Record.list文件,打开内容为“{"status":{"code":"6","message":"\u57df\u540d\u7f16\u53f7\u4e0d\u6b63\u786e","created_at":"2020-08-30 22:44:28"}}”,经过转换结果为域名编号不正确。

Post by 寒心浪子 on 2020, August 30, 10:46 PM 引用此文发表评论 #15

引用 我不知道我是谁 说过的话:
用了这个脚本,定期执行的时候,没执行一次,就会把我的PPPOE IPV6的前缀地址池给搞掉,我的地址池是来自ipv6 client客户端的,不知道这个bug能不能修复

你应该把这个放入PPP模板,让拨号引用这个模板,这样就不需要定时执行。只有断开重连的时候才会执行。

Post by 熊茂祥 on 2020, April 24, 10:31 AM 引用此文发表评论 #16

用了这个脚本,定期执行的时候,没执行一次,就会把我的PPPOE IPV6的前缀地址池给搞掉,我的地址池是来自ipv6 client客户端的,不知道这个bug能不能修复

Post by 我不知道我是谁 on 2020, April 14, 1:10 PM 引用此文发表评论 #17

引用 dafeida 说过的话:
请问应当如何使用呢?放在脚本里面,设置开机或者手动启动,执行了很久,都无法解析到地址。PPP模板里,应当如何设置?我的ppp-profile下有两个默认的(default,default-encryption),我应当新建一个还是就在这两个中的某个里面添加?除了on up放入这个脚本,其它项应当如何设置呢?谢谢帮忙解答!!!另外使用另一种API解析的话,脚本间隔执行时间应当设置多久比较好呢?

在当前PPPOE拨号使用的模板里添加,API提交建议10分钟提交一次。

Post by 熊茂祥 on 2020, April 12, 10:23 AM 引用此文发表评论 #18

引用 gengjingfeng 说过的话:
dnspod api 更新了,代码失效

这个问题月底回去了检查。

Post by 熊茂祥 on 2020, April 12, 10:20 AM 引用此文发表评论 #19

请问应当如何使用呢?放在脚本里面,设置开机或者手动启动,执行了很久,都无法解析到地址。PPP模板里,应当如何设置?我的ppp-profile下有两个默认的(default,default-encryption),我应当新建一个还是就在这两个中的某个里面添加?除了on up放入这个脚本,其它项应当如何设置呢?谢谢帮忙解答!!!另外使用另一种API解析的话,脚本间隔执行时间应当设置多久比较好呢?

Post by dafeida on 2020, April 9, 6:29 AM 引用此文发表评论 #20

Records:2412

发表评论

评论内容 (必填):