1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | python comments" style="font-variant: inherit; font-stretch: inherit; margin: 0px !important; padding: 0px !important; border: 0px !important; font-size: 1em !important; line-height: 1.1em !important; font-family: Monaco, Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace !important; vertical-align: baseline !important; color: rgb(0, 130, 0) !important; background: none !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; width: auto !important; box-sizing: content-box !important; direction: ltr !important; box-shadow: none !important; display: inline !important;">#!/usr/bin/env python #-*- coding:utf-8 -*- import httplib, urllib import socket import time params = dict ( login_email = "email" , # replace with your email login_password = "password" , # replace with your password format = "json" , domain_id = 100 , # replace with your domain_od, can get it by API Domain.List record_id = 100 , # replace with your record_id, can get it by API Record.List sub_domain = "www" , # replace with your sub_domain record_line = "默认" , ) current_ip = None def ddns(ip): params.update( dict (value = ip)) headers = { "Content-type" : "application/x-www-form-urlencoded" , "Accept" : "text/json" } conn = httplib.HTTPSConnection( "dnsapi.cn" ) conn.request( "POST" , "/Record.Ddns" , urllib.urlencode(params), headers) response = conn.getresponse() print response.status, response.reason data = response.read() print data conn.close() return response.status = = 200 def getip(): sock = socket.create_connection(( 'ns1.dnspod.net' , 6666 )) ip = sock.recv( 16 ) sock.close() return ip if __name__ = = '__main__' : while True : try : ip = getip() print ip if current_ip ! = ip: if ddns(ip): current_ip = ip except Exception, e: print e pass time.sleep( 30 ) |
替换上你的Email,密码,域名ID,记录ID等参数,就可以运行了。 会在后台一直运行,每隔30秒检查一遍IP,如果修改了就更新IP。
获得domain_id可以用
1 | curl curl -k https: //dnsapi .cn /Domain .List -d "login_email=xxx&login_password=xxx" |
获得record_id类似
1 | curl -k https: //dnsapi .cn /Record .List -d "login_email=xxx&login_password=xxx&domain_id=xxx" |
加入开机自动运行的方法:
编辑/etc/rc.local文件,在“exit 0”那一行前面加上一行
1 | su root -c "python /home/pypod.py" |
原文链接:http://shumeipai.nxez.com/2013/09/17/dnspod-update-dynamic-ip-resolution.html
版权声明
1.本站大部分下载资源收集于网络,不保证其完整性以及安全性,请下载后自行测试。
2.本站资源仅供学习和交流使用,版权归资源原作者所有,请在下载后24小时之内自觉删除。
3.若作商业用途,请购买正版,由于未及时购买和付费发生的侵权行为,与本站无关。
4.若内容涉及侵权或违法信息,请联系本站管理员进行下架处理,邮箱ganice520@163.com(本站不支持其他投诉反馈渠道,谢谢合作)
- 上一篇: 使用ngrok将树莓派web服务映射到公网
- 下一篇: 树莓派实现DDNS(PHP计划任务)
发表评论