Skip to content

Instantly share code, notes, and snippets.

@qizhihere
Forked from chuangbo/README.md
Last active November 13, 2015 09:05
Show Gist options
  • Save qizhihere/f97ec6aa6adfd0b46487 to your computer and use it in GitHub Desktop.
Save qizhihere/f97ec6aa6adfd0b46487 to your computer and use it in GitHub Desktop.
Python dynamic DNSPod DNS Script

替换上你的Email,密码,域名ID,记录ID等参数,就可以运行了。 会在后台一直运行,每隔60秒检查一遍IP,如果修改了就更新IP。

获得domain_id可以用curl curl -k https://dnsapi.cn/Domain.List -d "login_email=xxx&login_password=xxx"

获得record_id类似 curl -k https://dnsapi.cn/Record.List -d "login_email=xxx&login_password=xxx&domain_id=xxx"

#!/usr/bin/env python2
#-*- coding:utf-8 -*-
import httplib, urllib
import time
params = dict(
login_email="qizhihere@gmail.com", # replace with your email
login_password="7,apiwL$PQ_t6", # replace with your password
format="json",
domain_id=21032975, # replace with your domain_od, can get it by API Domain.List
record_id=127440689, # replace with your record_id, can get it by API Record.List
sub_domain="pc", # 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():
content = urllib.urlopen('http://icanhazip.com').read()
ip = content.strip()
return ip
if __name__ == '__main__':
while True:
print ('-' * 20) + ' BEGIN ' + ('-' * 20)
print 'At: %s' % time.strftime('%Y/%m/%d %H:%M:%S')
try:
ip = getip()
print ip
if current_ip != ip:
if ddns(ip):
current_ip = ip
except Exception, e:
print e
pass
print ('-' * 21) + ' END ' + ('-' * 21) + "\n"
time.sleep(60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment