找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 6042|回复: 9

用于Tomato路由器的动态域名脚本(dnspod DDNS API)轻松绑定自己的域名

[复制链接]
发表于 2015-4-11 01:49 | 显示全部楼层 |阅读模式
简易版:
  1. #!/opt/bin/bash

  2. source /etc/profile

  3. log_msg()
  4. {
  5.         logger "DDNS        $@"
  6. }

  7. cd /root

  8. CURRENTIP=`ifconfig ppp0 | grep -o '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*' | head -1`
  9. LATESTIP=''
  10. if [ ! -f "latestip.txt" ] ; then
  11.         if [ -z $LATESTIP ]; then
  12.                 LATESTIP=`curl -s members.3322.org/dyndns/getip`
  13.         fi
  14.         if [ -z $LATESTIP ]; then
  15.                 LATESTIP=`curl -s www.123cha.com | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -n 1`
  16.         fi
  17.         if [ -z $LATESTIP ]; then
  18.                 LATESTIP=`curl -s 1111.ip138.com/ic.asp | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'`
  19.         fi
  20.         if [ -z $LATESTIP ]; then
  21.                 LATESTIP=`curl -s checkip.dyndns.com | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'`
  22.         fi
  23. cat > latestip.txt<<-EOF
  24. ${LATESTIP}
  25. EOF
  26. fi

  27. eval LASTIP=$(cat latestip.txt)

  28. echo latestip:$LATESTIP
  29. echo lastip:$LASTIP
  30. echo currentip:$CURRENTIP
  31. if [ $CURRENTIP = $LASTIP ]; then
  32.         echo 'nothing to do.'
  33. else
  34.         log_msg "submit new ip."
  35.         echo 'submit new ip.'
  36. cat > latestip.txt<<-EOF
  37. ${CURRENTIP}
  38. EOF
  39. # renew dns record
  40. # @cmheia.com
  41.         curl -s --cacert /opt/etc/cacert.pem -X POST https://dnsapi.cn/Record.Ddns -d 'login_email=api@dnspod.com&login_password=password&format=json&domain_id=11111111&record_id=22222222&record_line=%E9%BB%98%E8%AE%A4'
  42. # *.cmheia.com
  43.         curl -s --cacert /opt/etc/cacert.pem -X POST https://dnsapi.cn/Record.Ddns -d 'login_email=api@dnspod.com&login_password=password&format=json&domain_id=11111111&record_id=33333333&record_line=%E9%BB%98%E8%AE%A4&sub_domain=*'
  44. fi
复制代码
高级版:
下载地址


使用方法:
  • 填写自己的域名信息
  • 脚本保存为 /opt/etc/ddns.sh
  • 添加定时任务
    1. chmod +700 /opt/etc/ddns.sh
    2. cru a ddns "*/5 * * * * /opt/etc/ddns.sh"
    复制代码



FAQ:
有啥不懂的点这里

本帖子中包含更多资源

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

×
我的恩山、我的无线 The best wifi forum is right here.
发表于 2015-4-11 06:57 来自手机 | 显示全部楼层
不用加端口?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2015-4-11 08:59 | 显示全部楼层
xvalue2=$(nvram get wan_ipaddr)
用 nvram获取外网IP应该能更方便些吧。另外,放在“当WLAN联机”中,感觉比定时查询更及时。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2015-4-11 11:11 | 显示全部楼层
和自带的有什么优势???
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2015-4-11 12:12 | 显示全部楼层
不错,能动态更新dnspod
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2015-4-11 13:34 | 显示全部楼层
技术贴,支持一下
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2015-4-17 07:14 来自手机 | 显示全部楼层
看看,不过能详细点吗?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2015-8-7 20:12 | 显示全部楼层
能不能内网穿透
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2015-8-8 12:58 | 显示全部楼层
你的路由器什么型号啊, 还可以建网站 ?  
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2015-8-8 13:29 | 显示全部楼层
不加端口?这都可以?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 00:55

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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

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