Created
March 27, 2013 15:56
-
-
Save lenage/5255350 to your computer and use it in GitHub Desktop.
Update DNSPod recored use Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
#-*- coding:utf-8 -*- | |
import httplib, urllib | |
import socket | |
import time | |
import sys | |
#replace with your sub_domain and your record_id, which can get it by API Record.List | |
# how to get record_id: https://gist.github.com/kennyz/0afc809baabd8223fddf | |
ddns_domains = {"*":21201661, "@":21231504,"www":21251160}; | |
params = dict( | |
login_email="email", # replace with your email | |
login_password="password", # replace with your password | |
format="json", | |
domain_id=3087226, # replace with your domain_od, can get it by API Domain.List | |
record_line="默认", | |
) | |
current_ip = None | |
def ddns(ip,domain): | |
params.update(dict(value=ip,sub_domain=domain,record_id=ddns_domains[domain])) | |
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) | |
print params; | |
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(('ns2.dnspod.net', 6666)) | |
ip = sock.recv(16) | |
sock.close() | |
return ip | |
if __name__ == '__main__': | |
try: | |
ip = getip() | |
print ip | |
if current_ip != ip: | |
for domain in ddns_domains: | |
ddns(ip, domain); | |
current = ip | |
#if ddns(ip): | |
# current_ip = ip | |
except Exception, e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment