找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 6587|回复: 16

dnspod动态IP客户端

[复制链接]
发表于 2013-2-1 12:05 | 显示全部楼层 |阅读模式
本帖最后由 freefall12 于 2013-2-21 20:18 编辑

用shell写了个动态ip dnspod客户端,分享一下
  1. #!/bin/sh
  2. #Authored by Benson Huang
  3. #More details at www.zhetenger.com

  4. #for openwrt only. source the path variable set in /etc/profile
  5. is_openwrt=`uname -a | grep -o OpenWrt`

  6. if [ $is_openwrt ] && [ -f /etc/profile ]

  7. then

  8. . /etc/profile

  9. fi

  10. #import dnspod configuration file(DNSPOD login credentials, domain,subdomain,domain_id and record_id).To prevent the password visible to anyone who stumble across this file, the password is obscured using a string of meaningless letters and numbers.

  11. if [ -f ~/.dnspodrc ]

  12. then
  13. . ~/.dnspodrc

  14. else

  15. read -p "email:(e.g test@gmail.com)" email
  16. read -p "password:" password
  17. read -p "sub_domain name:(e.g @, www, ftp, etc)" subdomain
  18. read -p "main domain: (e.g zhetenger.com)" domain

  19. echo "$email" | sed 's/.*@.*\.com/email=&/' > ~/.dnspodrc
  20. echo "$password" | sed 's/.*/password=secure&protection/' >> ~/.dnspodrc
  21. echo "$subdomain" | sed 's/.*/subdomain=&/' >> ~/.dnspodrc
  22. echo "$domain" | sed 's/.*/domain=&/' >> ~/.dnspodrc

  23. fi

  24. #parse password from ~/.dnspodrc.

  25. password=$(sed -n '/password/{
  26. s/secure//
  27. s/protection//
  28. s/password=//
  29. p
  30. }' ~/.dnspodrc)

  31. pub_ip_addr=$(curl -s http://checkip.dyndns.com | sed -n 's/.*: \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/p')
  32. cert_file="/etc/ssl/cacert.pem" #specify the certificate file path
  33. dns_url="https://dnsapi.cn" #DNSPOD API URL
  34. data="login_email=$email&login_password=$password&format=json&lang=en&" #assign login credentials and other parameters to the variable data

  35. upload_data () {
  36. curl -s -k -A "dnspod" -d $data$2 $dns_url/$1
  37. }

  38. # the following codes will be skipped if domain_id and record_id have already been set in ~/.dnspodrc.
  39. exist_id=`grep -o 'domain_id=[0-9]*' ~/.dnspodrc`

  40. if [ -z "$exist_id" ]

  41. then
  42. domain_id=`upload_data Domain.Info domain=$domain | sed -rn 's/.*("domain":\{.[^}]+\}).*/\1/g;s/.*"id":"([0-9]+)".*/\1/p'`

  43. record_id=$(upload_data Record.List "domain_id=$domain_id" | sed -rn "s/.*("records":\[.[^]]+\]).*/\1/g;s/.*\{"id":"([0-9]+)","name":"@".*"type":"A".*/\1/p")

  44. cat >> ~/.dnspodrc <<EOF
  45. domain_id=$domain_id
  46. record_id=$record_id
  47. EOF
  48. fi

  49. #update dns record
  50. upload_data Record.Modify "domain_id=$domain_id&record_id=$record_id&record_type=A&record_line=默认&ttl=600&value=$pub_ip_addr"
复制代码
不会使用的,可以参考这里dnspod动态ip解析脚本
我的恩山、我的无线 The best wifi forum is right here.
发表于 2013-2-1 12:50 | 显示全部楼层
无法显示网页。。。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2013-2-1 14:47 | 显示全部楼层
┽→寂寞·不畏 发表于 2013-2-1 12:50
无法显示网页。。。

刚修改了下服务器的grub,搞的不能启动了,现在OK了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2013-2-1 15:44 | 显示全部楼层
技术贴要顶。。。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2013-2-1 16:37 来自手机 | 显示全部楼层
算是ddns吗?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2013-2-1 16:59 | 显示全部楼层
fclql 发表于 2013-2-1 16:37
算是ddns吗?

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

使用道具 举报

发表于 2013-2-1 17:27 | 显示全部楼层
原生opewnrt的ddns就很好用了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2013-2-1 18:42 | 显示全部楼层
fclql 发表于 2013-2-1 17:27
原生opewnrt的ddns就很好用了

那不一样的。自带的基本只能二级域名解析,即test.3322.org这样的域名,如果你想解析自己的com 或net域名,像www.zhetenger.com就得付费,而且还没有linux系统可用的。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2013-2-2 11:00 | 显示全部楼层
基于dnspod的?
支持主域名的?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2013-2-2 13:52 | 显示全部楼层
这里有IPK,安装一下就可以。
http://www.vinoca.org/2012/06/10 ... %E5%8A%9F%E8%83%BD/
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2013-2-20 11:50 | 显示全部楼层
这个应该 不支持 80端口吧? 80端口应该不能直接访问
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2013-2-21 20:11 | 显示全部楼层
apptony 发表于 2013-2-20 11:50
这个应该 不支持 80端口吧? 80端口应该不能直接访问

这个跟端口没什么关系
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2013-7-15 15:27 | 显示全部楼层
学习了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2013-7-18 23:14 | 显示全部楼层
没玩路由器之前在自己的NAS上用过,挺不错的。。挂自己的域名
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2013-7-20 15:06 | 显示全部楼层
自己的域名CNAME到免费DDNS即可
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-25 20:01

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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

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