-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
46 lines (34 loc) · 1 KB
/
example.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
41
42
43
44
45
46
from enum import Enum
from pydantic import BaseModel
from pydantic_requests import PydanticSession
class DNSStatus(Enum):
"""DNS OP response codes.
ref: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
"""
# No Error = 0
NoError = 0
# Format Error = 1
FormErr = 1
# Server Failure
ServFail = 2
# Non-Existent Domain
NXDomain = 3
class DNSQuery(BaseModel):
Status: DNSStatus
class Config:
"""Configure DNS query."""
allow_mutation = False
arbitrary_types_allowed = True
with PydanticSession(
{200: DNSQuery}, headers={"accept": "application/dns-json"}
) as session:
domain = "dz0ny.xyz"
res = session.get(
"https://cloudflare-dns.com/dns-query", params={"name": domain, "type": "NS"}
)
res.raise_for_status()
query: DNSQuery = res.model
if query.Status != DNSStatus.NXDomain:
print("Domain is registered.")
else:
print("Domain is registered.")