Dnspod API call Script

Source: Internet
Author: User
Tags in domain

[[email protected] dnspod]# cat dnspod.sh #!/bin/bashfunction menu () {Clearecho "*********************dnspod********** "Echo" *       1, will accelerate the Le CNAME batch modified to dnspod          * "echo" *       2, the IP batch modified to dnspod* "echo" *       3, a single domain modification         * " echo "*       4, Exit             *" echo "***************************************************" Read-p "Please enter the number:" Numberread-p " Please enter D token: "Number2}while truedomenucase $number in1) python/python/saltnew/dnspod/dnspod.py batch_jiasule $number 2read- P "Enter continue:";; 2) python/python/saltnew/dnspod/dnspod.py batch_dnspod $number 2read-p "enter continue:";; 3) python/python/saltnew/dnspod/dnspod.py None $number 2read-p "Enter continue:";; *) exit; Esacdone

  

[email protected] dnspod]# cat dnspod.py #!/bin/python#-*-coding:utf-8-*-import urllibimport urllib2import OS, sys,json,demjson,fileinput# processing POST Request Def post (url,data): req = urllib2. Request (URL) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "Text/json", "User-agent": "DNS pod-python/0.01 ([email protected]; dnspod.cn API v2.8) "} data = Urllib.urlencode (data,headers) opener = Urllib2.build_opener (urllib2.    Httpcookieprocessor ()) response = Opener.open (req, data) return Response.read () #主函数def Main (Batch,login_code): #获取域名列表 posturldomain= ' https://dnsapi.cn/Domain.List ' datadomain={' login_email ': ' [email protected] ', ' login_ Password ': ' 123456 ', ' format ': ' JSON ', ' Login_code ': Login_code} domain={} records={} number=0 numbertwo=0 Batch list={} jiasulelist={} dnspodlist={} for I in Demjson.decode (str (post (Posturldomain,datadomain))) [U ' domains '] [:]:   Number+=1domain[number]={str (i[u ' name '): STR (i[u ' ID ')} For Key,value in Domain.items ():p rint key,value numb=input ("Please input number:") Domain_number=domain[numb].valu ES () [0] #获取二级域名列表 posturlrecordlist= ' https://dnsapi.cn/Record.List ' datarecordlist={' login_email ': ' [Email&nbs P;protected] ', ' login_password ': ' 123456 ', ' format ': ' JSON ', ' domain_id ':d omain_number, ' Login_code ': Login_code} for I In Demjson.decode (str (post (posturlrecordlist,datarecordlist))) [u ' Records '][:]:numbertwo+=1batchlist[i[u ' name '] =STR (i[u ' id ')) records[numbertwo]={str (i[u ' name ']): str (i[u ' id ')} #批量恢复 if batch = = "Batch_jiasule": For line in Filei Nput.input ("/python/saltnew/dnspod/jiasule.txt"): Name=line.strip (' \ n '). Split (') [0] Cname=line.strip (' \ n '). Split (') [1] records_id=batchlist[name] jiasulelist[name]={cname:records_id} posturlmodify_batch= ' Https://dnsapi . cn/record.modify ' datamodify_batch={' login_email ': ' [email protected] ', ' login_password ': ' 123456 ', ' format ': ' JSON ', ' domain_id ':d omain_number, ' sub_domain ': Name, ' recOrd_type ': ' CNAME ', ' record_line ': U ' default '. Encode ("UTF8"), ' value ': CNAME, ' record_id ': records_id, ' Login_code ': login_ Code} print post (Posturlmodify_batch,datamodify_batch) sys.exit (1) If batch = = "Batch_dnspod": For line in fi Leinput.input ("/python/saltnew/dnspod/dnspod.txt"): Name=line.strip (' \ n '). Split (') [0] Ip=line.stri P (' \ n '). Split (') [1] records_id=batchlist[name] dnspodlist[name]={ip:records_id} posturl modify_dns= ' https://dnsapi.cn/Record.Modify ' datamodify_dns={' login_email ': ' [email protected] ', ' Login_pass Word ': ' 123456 ', ' format ': ' JSON ', ' domain_id ':d omain_number, ' sub_domain ': Name, ' Record_type ': ' A ', ' record_line ': U ' Default '. Encode ("UTF8"), ' value ': IP, ' record_id ': records_id, ' Login_code ': Login_code} print post (posturlmodify_dns,data Modify_dns) Sys.exit (1) #单个修改 for Key,value in Records.items ():p rint key,value numb2=input ("Please input n Umber: ") records_number=records[numb2].values () [0] Records_name=records[numb2].keys () [0] Record_type=raw_input ("Please enter record type:") record_ip=raw_input ("Please enter record value:") #修改某个二级域名的记录类型与记录值 posturlmodify= ' https://dnsapi.cn/Record.Modify ' datamodify={' login_email ': ' [Email protec Ted] ', ' login_password ': ' 123456 ', ' format ': ' JSON ', ' domain_id ':d omain_number, ' sub_domain ': records_name, ' Record_ Type ': Record_type, ' record_line ': U ' default '. Encode ("UTF8"), ' value ': record_ip, ' record_id ': records_number, ' Login_code ' : Login_code} print post (posturlmodify,datamodify) if __name__ = = ' __main__ ': Main (sys.argv[1],sys.argv[2])

  

Dnspod.txttesttest 2.2.2.2testtest2 1.1.1.1jiasule.txttesttest 767b885d566c6111.cdn.jiashule.com.testtest2 B97c167111aba5dc.cdn.jiashule.com.

  

Dnspod API call Script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.