批量更新dnspod的子域名ip

 
#!/usr/bin/env python
#-*- coding:utf-8 -*-
 
import httplib, urllib
import socket
import time
import os
import sys
import simplejson as json
 
reload(sys)
sys.setdefaultencoding('utf-8')
 
params0 = dict(
	login_email="test@xxx.com", # dnspod帐号
	login_password="tttttttt", # dnspod密码
	format="json"
)
 
params = params0.copy()  
params.update(dict(
	domain_id=0, #域名ID
	record_id=0, #记录ID
	sub_domain='test',    #子域名
	record_line="默认" #默认值
))
 
def domainList():
	headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
	conn = httplib.HTTPSConnection("dnsapi.cn")
	conn.request("POST", "/Domain.List", urllib.urlencode(params0), headers)
	response = conn.getresponse()
	data = response.read()
	print data
	conn.close()
	return data
 
def recordList(_domain):
	params0.update(dict(domain=_domain))
	headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json"}
	conn = httplib.HTTPSConnection("dnsapi.cn")
	conn.request("POST", "/Record.List", urllib.urlencode(params0), headers)
	response = conn.getresponse()
	data = response.read()
	print data
	conn.close()
	return data
 
 
def ddns(domain_id,record_id,sub_domain,ip):
	params.update(dict(domain_id=domain_id,record_id=record_id,sub_domain=sub_domain,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()
	data = response.read()
	print data
	conn.close()
	return response.status == 200
 
 
 
if __name__ == '__main__':
 
	ipx=dict(
		dd1=    	        '220.181.111.86',
		dd2=	 	'220.181.111.86',
		dd3=		'220.181.111.86',
		dd4=		'220.181.111.86'
 
	)
 
	#ipx=dict(train7='1.2.3.4')
 
  	str_json = recordList('hehehehe.com')
	dict_o = json.loads(str_json)
	domain_id =  dict_o['domain']['id']
 
 
	for k, v in ipx.iteritems():
		for x in dict_o['records']:
			sub_domain =  x['name']
			if(sub_domain==k):
				old_ip = x['value']
				ip =v
				record_id=x['id']
				print  record_id
				if old_ip==ip:
					print 'True'					
				else:
					print 'False'
                                        #ddns(domain_id,record_id,sub_domain,ip) #更改域名ip

原创文章,转载请注明: 转载自海波无痕

本文链接地址: 批量更新dnspod的子域名ip

文章的脚注信息由WordPress的wp-posturl插件自动生成

此条目发表在server分类目录,贴了, , , , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论链接可以 移除 nofollow.