1 Star 0 Fork 0

RTsien / Code Fragments

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pypod-dnspod动态域名.py 1.33 KB
一键复制 编辑 原始数据 按行查看 历史
Rtsien 提交于 2014-05-26 14:18 . first commit
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import httplib, urllib
import socket
import time
params = dict(
login_email="XX@XX.com", # replace with your email
login_password="XXXX", # replace with your password
format="json",
domain_id=XXXXX, # replace with your domain_od, can get it by API Domain.List
record_id=XXXXX, # replace with your record_id, can get it by API Record.List
sub_domain="@", # 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(60)
C
1
https://gitee.com/rtsien/Code-Fragments.git
git@gitee.com:rtsien/Code-Fragments.git
rtsien
Code-Fragments
Code Fragments
master

搜索帮助