In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
Xiaosheng blog: http://xsboke.blog.51cto.com
-Thank you for your reference. If you have any questions, you are welcome to communicate.
First of all, here, CloudFlare is a DNS provider (as I understand it), he provides a lot of services (HTTPS/CDN, etc.), you can go to the official website to see for yourself: www.cloudflare.com
CloudFlare recommends using the curl command of linux to use the developed API
Because shell can not handle the json data returned by CloudFlare very well, on the basis of using shell, python script is added.
A total of four script files are used together in this file:
Domians.txt: used to store the domain name to be added env.env: store various variables filter_zone_id.py: used to filter the data returned by CloudFlare (filter out the domain name and its region ID) filter_dns_id.py: used to filter the data returned by CloudFlare (filter out the resolution record and its area ID) main.sh: store the linux command, and execute this script
First, there is no need to introduce domain.txt, just write the top-level domain name into it, one by one.
II. Env.env
#! / bin/bash# generic variable # current directory PWD=$ (pwd) PYTHON=$ (which python) ECHO=$ (which echo) # here DNS refers to the resolution record # account CF_API_EMAIL=CloudFlare login account # key CF_API_KEY= view "Global KEY" # organization name organization_name= "organization name" # organization IDorganization_id= "organization ID" # set the alias "CNAME" CONTENT_ to be resolved for CNAME and IPCONTENT_CNAME= domain names in the user information Alias IP#get_zone_id.cf to be resolved for an IP= domain name-- JSON data returned by Cloudflare when storing a new domain name # get_dns_id.cf-- storing JSON data returned by Cloudflare when obtaining DNS_ID # filter_zone_id.py-- used to filter the domain name and its corresponding region ID from "get_zone_id.cf" and write to the file "zone_id.cf" "# filter_dns_id.py-used to filter out DNS_ID and its DNS_NAME from" get_dns_id.cf "and write to the file" dns_id.cf "
II. Main.sh
#! / bin/bashsource. / env.env# added domain name for domain in $(cat $PWD/domains.txt) do curl-X POST-H "X-Auth-Key: ${CF_API_KEY}"\-H "X-Auth-Email: ${CF_API_EMAIL}"\-H "Content-Type: application/json"https://api.cloudflare.com/client/v4/zones"\-data'{" name ":"'"${domain}"'" "jump_start": true, "organization": {"name": "'" ${organization_name} "'", "id": "'" ${organization_id} "'"}}'> > $PWD/get_zone_id.cf ${ECHO}-e "\ n" > > $PWD/get_zone_id.cfdone# executes the python script Filter out the domain name area ID$PYTHON $PWD/filter_zone_id.py# to get the DNS ID list while read linedo ZONE_NAME=$ (${ECHO} "$line" | awk'{print $1}') ZONE_ID=$ (${ECHO} "$line" | awk'{print $2}') curl-X GET "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records"\-H" X-Auth -Email: ${CF_API_EMAIL} "- H" X-Auth-Key: ${CF_API_KEY} "\-H" Content-Type: application/json "> > $PWD/get_dns_id.cf ${ECHO}-e"\ n "> > $PWD/get_dns_id.cfdone < $PWD/zone_id.cf# execute python script Filter out DNS_ID$PYTHON $PWD/filter_dns_id.py# delete DNS record # you also need to specify a region ID to delete a DNS record. The region DI of each domain name is different, so make a judgment Determine whether the DNS_NAME blurred matches the ZONE_NAME# fetched before using the ZONE_IDwhile read zonedo ZONE_NAME=$ (${ECHO} "$zone" | awk'{print $1}') ZONE_ID=$ (${ECHO} "$zone" | awk'{print $2}') while read dns do DNS_NAME=$ (${ECHO} "$dns" | awk'{print $1}') DNS_ID=$ (${ ECHO} "$dns" | awk'{print $2}') if [["* $DNS_NAME" = ~ "$ZONE_NAME"]] then curl-X DELETE "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${DNS_ID}"\-H" Xmai AuthorityE mail CF_API_EMAIL} "\"\ -H "X Content-Type:application/json Content-Type:application/json" fi done < $PWD/dns_id.cfdone < $PWD/zone_id.cf# added DNS record # TTL=1 for automatic # proxied=true using CF CDN Equal to false does not use # data incoming variable format: "'" $EVN "'" # set variable while read linedo ZONE_NAME=$ (${ECHO} "$line" | awk'{print $1}') ZONE_ID=$ (${ECHO} "$line" | awk'{print $2}') curl-X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records"\-H" "X Content-Type:application/json Content-Type:application/json"\-H "X Content-Type:application/json type": "A" "name": "@", "content": "'" ${CONTENT_IP} "'", "ttl": 1, "priority": 10 "proxied": true} 'curl-X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records"\-H" XmaiAuthmaieMailVERVER ${CF_API_EMAIL} "\-H" XmuraAuthmaKey POST ${CF_API_KEY} "\-H" Content-Type:application/json "\-- data' {" type ":" CNAME " "name": "www", "content": "'" ${CONTENT_CNAME} "'", "ttl": 1, "priority": 10 "proxied": false} 'curl-X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records"\-H" XmaiAuthmaieMailVERVER ${CF_API_EMAIL} "\-H" XmuraAuthmaKey POST ${CF_API_KEY} "\-H" Content-Type:application/json "\-- data' {" type ":" CNAME " "name": "m", "content": "'" ${CONTENT_CNAME} "'", "ttl": 1, "priority": 10, "proxied": false} 'done < $PWD/zone_id.cf
III. Filter_zone_id.py
#! / usr/bin/env python#*- coding:utf-8-* # Open the file to obtain the data returned after the domain name has been successfully added, and then get the region ID# of the domain name through the region ID to obtain the DNS list import jsonimport osimport traceback#traceback complete output error information # str (e) only gives the exception information, excluding the type of exception information, such as 1 repr 0 exception information # repr (e) gives more complete exception information Include the type of exception information, such as PWD = os.getcwd () PWD_GET = PWD+'/get_zone_id.cf'PWD_ZONE = PWD+'/zone_id.cf'ERROR_FILE = PWD+'/zone_error.log'# of exception information of 1bank 0 read the string returned when the domain name is added, and write it to the dictionary in a loop To filter out the domain name area IDwith open (PWD_GET) 'r') as file: I = 0j = 0 dict = {} list = [] for line in file: if line.strip = = "" or line = = "\ n" or line = "\ n": continue try: dict [I] = json.loads (line) iTunes 1 except Exception as e: jacks 1 with open (ERROR_FILE) As file: title = "-\ t\ t% d error message\ t\ t -"% (j) + "\ n" # info = "error message:" + traceback.format_exc () + "\ n" info = "error message:" + repr (e) + "\ n "mation =" error line: "+ line +"\ n "file.writelines (title) file.writelines (info) file.writelines (mation) continue# get all key Then iterate through the area IDkeys_list = dict.keys () for key in keys_list: ID=dict [key] ['result'] [' id'] NAME=dict [key] ['result'] [' name'] with open (PWD_ZONE,'a+') as file: line = NAME + "+ ID +"\ n "file.writelines (line)
IV. Filter_dns_id.py
#! / usr/bin/env python#*- coding:utf-8-* # Open the file to read DNS IDimport jsonimport osPWD = os.getcwd () PWD_GET = PWD+'/get_dns_id.cf'PWD_DNS = PWD+'/dns_id.cf'# returned by cloudflare, read the string returned when getting DNS ID, and write it to the dictionary in a loop In order to filter out DNS IDwith open (PWD_GET) 'r') as file: I = 0 dict = {} for line in file: if line.strip = = "" or line = "\ n" or line = = "\ n": continue dict [I] = json.loads (line) i+=1key_list = dict.keys () for key in key_list: list = dict [key] ['result'] # A domain name may have multiple DNS records Cloudflare returns a list, in which is a dictionary, and # a key-values represents a DNS record, so here you need to traverse the dictionary in the list # by fetching the index value of the list Loop the dictionary for i in list: with open (PWD_DNS,'a+') as file: line = I ['name'] + "+ I [' id'] +"\ n "file.writelines (line)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.