码迷,mamicode.com
首页 > 其他好文 > 详细

dnspod单个修改与批理修改脚本

时间:2016-02-16 18:19:14      阅读:484      评论:0      收藏:0      [点我收藏+]

标签:


 1 [root@localhost dnspod]# cat dnspod.sh 
 2 #!/bin/bash
 3 function menu() {
 4 clear
 5 echo "*********************Dnspod************************"
 6 echo "*       1,将加速乐cname批量修改到dnspod          *"
 7 echo "*       2, 将ip批量修改到dnspod            *"
 8 echo "*       3, 单个域名修改                     *"
 9 echo "*       4, 退出                         *"
10 echo "***************************************************"
11 read -p "请输入编号: " number
12 read -p "请输入D令牌: " number2
13 }
14 while true
15 do
16     menu
17     case $number in
18     1)
19     python /python/saltnew/dnspod/dnspod.py batch_jiasule $number2
20     read -p "回车继续: ";;
21     2)
22     python /python/saltnew/dnspod/dnspod.py batch_dnspod $number2
23     read -p "回车继续: ";;
24     3)
25     python /python/saltnew/dnspod/dnspod.py none $number2
26     read -p "回车继续: ";;
27     *)
28     exit;;
29     esac
30 done

 

 [root@localhost dnspod]# cat dnspod.py
1
#!/bin/python 2 #-*- coding: utf-8 -*- 3 import urllib 4 import urllib2 5 import os,sys,json,demjson,fileinput 6 7 #处理post请求 8 def post(url,data): 9 req = urllib2.Request(url) 10 headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/json", "User-Agent": "dnspod-python/0.01 (im@chuangbo.li; DNSPod.CN API v2.8)"} 11 data = urllib.urlencode(data,headers) 12 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) 13 response = opener.open(req, data) 14 return response.read() 15 16 #主函数 17 def main(batch,login_code): 18 19 #获取域名列表 20 posturlDomain=https://dnsapi.cn/Domain.List 21 dataDomain={login_email:xxx@xxx.com,login_password:xxx,format:json,login_code:login_code} 22 Domain={} 23 records={} 24 number=0 25 numbertwo=0 26 batchlist={} 27 jiasulelist={} 28 dnspodlist={} 29 for i in demjson.decode(str(post(posturlDomain,dataDomain)))[udomains][:]: 30 number+=1 31 Domain[number]={str(i[uname]):str(i[uid])} 32 for key,value in Domain.items(): 33 print key,value 34 numb=input("please input number: ") 35 domain_number=Domain[numb].values()[0] 36 37 #获取二级域名列表 38 posturlrecordlist=https://dnsapi.cn/Record.List 39 datarecordlist={login_email:xxx@xxx.com,login_password:xxx,format:json,domain_id:domain_number,login_code:login_code} 40 for i in demjson.decode(str(post(posturlrecordlist,datarecordlist)))[urecords][:]: 41 numbertwo+=1 42 batchlist[i[uname]]=str(i[uid]) 43 records[numbertwo]={str(i[uname]):str(i[uid])} 44 45 #批量恢复 46 if batch == "batch_jiasule": 47 for line in fileinput.input("/python/saltnew/dnspod/jiasule.txt"): 48 name=line.strip(\n).split( )[0] 49 cname=line.strip(\n).split( )[1] 50 records_id=batchlist[name] 51 jiasulelist[name]={cname:records_id} 52 posturlmodify_batch=https://dnsapi.cn/Record.Modify 53 datamodify_batch={login_email:xxx@xxx.com,login_password:xxx,format:json,domain_id:domain_number,sub_domain:name,record_type:CNAME,record_line:u默认.encode("utf8"),value:cname,record_id:records_id,login_code:login_code} 54 print post(posturlmodify_batch,datamodify_batch) 55 sys.exit(1) 56 if batch == "batch_dnspod": 57 for line in fileinput.input("/python/saltnew/dnspod/dnspod.txt"): 58 name=line.strip(\n).split( )[0] 59 ip=line.strip(\n).split( )[1] 60 records_id=batchlist[name] 61 dnspodlist[name]={ip:records_id} 62 posturlmodify_dns=https://dnsapi.cn/Record.Modify 63 datamodify_dns={login_email:xxx@xxx.com,login_password:xxx,format:json,domain_id:domain_number,sub_domain:name,record_type:A,record_line:u默认.encode("utf8"),value:ip,record_id:records_id,login_code:login_code} 64 print post(posturlmodify_dns,datamodify_dns) 65 sys.exit(1) 66 67 #单个修改 68 for key,value in records.items(): 69 print key,value 70 numb2=input("please input number: ") 71 records_number=records[numb2].values()[0] 72 records_name=records[numb2].keys()[0] 73 record_type=raw_input("请输入记录类型: ") 74 record_ip=raw_input("请输入记录值: ") 75 76 #修改某个二级域名的记录类型与记录值 77 posturlmodify=https://dnsapi.cn/Record.Modify 78 datamodify={login_email:xxx@xxx.com,login_password:xxx,format:json,domain_id:domain_number,sub_domain:records_name,record_type:record_type,record_line:u默认.encode("utf8"),value:record_ip,record_id:records_number,login_code:login_code} 79 print post(posturlmodify,datamodify) 80 81 if __name__ == __main__: 82 main(sys.argv[1],sys.argv[2])
1 [root@localhost dnspod]# cat dnspod.txt 
2 www 1.1.1.1
3 
4 [root@localhost dnspod]# cat jiasule.txt 
5 www 5644545644665.cdn.jiashule.com.

 

dnspod单个修改与批理修改脚本

标签:

原文地址:http://www.cnblogs.com/zenghui940/p/5193160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!