Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 1ee9567

Browse files
committed
function: handleShortResponse and doDnsSec
1 parent 7569da7 commit 1ee9567

File tree

2 files changed

+68
-56
lines changed

2 files changed

+68
-56
lines changed

test2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ def prepItem(d):
1515
print("")
1616
print(f"test domain: <<<<<<<<<< {d} >>>>>>>>>>>>>>>>>>>>")
1717

18+
1819
def xType(x):
1920
s = f"{type(x)}"
2021
return s.split("'")[1]
2122

23+
2224
def testItem(d):
2325
w = whois.query(
2426
d,
@@ -37,7 +39,7 @@ def testItem(d):
3739
# statuses can be a array of one empty string if no data
3840

3941
# not all values are always present it mainly depends on whet we see in the output of whois
40-
# if we return not None: the elements that ars always there ars domain_name and tld
42+
# if we return not None: the elements that ars always there ars domain_name , tld, dnssec
4143

4244
wd = w.__dict__
4345
for k, v in wd.items():

whois/_2_parse.py

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,69 @@ def cleanupWhoisResponse(
9595
return response
9696

9797

98+
def handleShortResponse(
99+
tld: str,
100+
dl: List,
101+
whois_str: str,
102+
verbose: bool = False,
103+
):
104+
if verbose:
105+
d = ".".join(dl)
106+
print(f"line count < 5:: {tld} {d} {whois_str}", file=sys.stderr)
107+
108+
s = whois_str.strip().lower()
109+
110+
# NOTE: from here s is lowercase only
111+
# ---------------------------------
112+
noneStrings = [
113+
"not found",
114+
"no entries found",
115+
"status: free",
116+
"no such domain",
117+
"the queried object does not exist",
118+
"domain you requested is not known",
119+
"status: available",
120+
]
121+
122+
for i in noneStrings:
123+
if i in s:
124+
return None
125+
126+
# ---------------------------------
127+
# is there any error string in the result
128+
if s.count("error"):
129+
return None
130+
131+
# ---------------------------------
132+
quotaStrings = [
133+
"limit exceeded",
134+
"quota exceeded",
135+
"try again later",
136+
"please try again",
137+
"exceeded the maximum allowable number",
138+
"can temporarily not be answered",
139+
"please try again.",
140+
"queried interval is too short",
141+
]
142+
143+
for i in quotaStrings:
144+
if i in s:
145+
raise WhoisQuotaExceeded(whois_str)
146+
147+
# ---------------------------------
148+
# ToDo: Name or service not known
149+
150+
# ---------------------------------
151+
raise FailedParsingWhoisOutput(whois_str)
152+
153+
def doDnsSec(whois_str: str):
154+
whois_dnssec: Any = whois_str.split("DNSSEC:")
155+
if len(whois_dnssec) >= 2:
156+
whois_dnssec = whois_dnssec[1].split("\n")[0]
157+
if whois_dnssec.strip() == "signedDelegation" or whois_dnssec.strip() == "yes":
158+
return True
159+
return False
160+
98161
def do_parse(
99162
whois_str: str,
100163
tld: str,
@@ -111,62 +174,9 @@ def do_parse(
111174
)
112175

113176
if whois_str.count("\n") < 5:
114-
if verbose:
115-
d = ".".join(dl)
116-
print(f"line count < 5:: {tld} {d} {whois_str}", file=sys.stderr)
117-
118-
s = whois_str.strip().lower()
119-
120-
# NOTE: from here s is lowercase only
121-
# ---------------------------------
122-
noneStrings = [
123-
"not found",
124-
"no entries found",
125-
"status: free",
126-
"no such domain",
127-
"the queried object does not exist",
128-
"domain you requested is not known",
129-
"status: available",
130-
]
131-
132-
for i in noneStrings:
133-
if i in s:
134-
return None
135-
136-
# ---------------------------------
137-
# is there any error string in the result
138-
if s.count("error"):
139-
return None
177+
return handleShortResponse(tld, dl, whois_str, verbose)
140178

141-
# ---------------------------------
142-
quotaStrings = [
143-
"limit exceeded",
144-
"quota exceeded",
145-
"try again later",
146-
"please try again",
147-
"exceeded the maximum allowable number",
148-
"can temporarily not be answered",
149-
"please try again.",
150-
"queried interval is too short",
151-
]
152-
153-
for i in quotaStrings:
154-
if i in s:
155-
raise WhoisQuotaExceeded(whois_str)
156-
157-
# ---------------------------------
158-
# ToDo: Name or service not known
159-
160-
# ---------------------------------
161-
raise FailedParsingWhoisOutput(whois_str)
162-
163-
# check the status of DNSSEC
164-
r["DNSSEC"] = False
165-
whois_dnssec: Any = whois_str.split("DNSSEC:")
166-
if len(whois_dnssec) >= 2:
167-
whois_dnssec = whois_dnssec[1].split("\n")[0]
168-
if whois_dnssec.strip() == "signedDelegation" or whois_dnssec.strip() == "yes":
169-
r["DNSSEC"] = True
179+
r["DNSSEC"] = doDnsSec(whois_str) # check the status of DNSSEC
170180

171181
# this is mostly not available in many tld's anymore, should be investigated
172182
# split whois_str to remove first IANA part showing info for TLD only

0 commit comments

Comments
 (0)