-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_dns_record.py
40 lines (28 loc) · 1.05 KB
/
check_dns_record.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import argparse
import requests
def get_dns_records(zone_id: str, api_token: str) -> dict:
"""
Get the DNS record of a domain name.
:param zone_id: The zone ID of the domain name
:param api_token: The API token
:return: dns_record
"""
url = f'https://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records'
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_token}'
}
response = requests.request('GET', url, headers=headers)
response_json = response.json()
return response_json['result']
def main():
parser = argparse.ArgumentParser(description='Get the DNS record of a domain name')
parser.add_argument('-z', '--zone_id', type=str, help='The zone ID of the domain name')
parser.add_argument('-t', '--api_token', type=str, help='The API token')
args = parser.parse_args()
# Get the DNS record
record = get_dns_records(zone_id=args.zone_id, api_token=args.api_token)
# Print the DNS record
print(record)
if __name__ == '__main__':
main()