Skip to content

Commit 452d329

Browse files
committed
rdap info first , if none try whois
1 parent 52623ab commit 452d329

28 files changed

Lines changed: 240 additions & 219 deletions

Makefile.tests

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,49 @@ TEST_OPTIONS_ALL = \
1212
# --------------------------------------------------
1313
# Tests
1414
# --------------------------------------------------
15-
test: test1 testwith test2 test3 test4
15+
test: prep test1 test2 test3 test4
16+
17+
prep:
18+
mkdir -p tmp
1619

1720
test1:
18-
./test1.py | tee tmp/$@.1
21+
$(COMMON_VENV) \
22+
$(PIP_INSTALL) -r requirements.txt; \
23+
./test1.py 2>tmp/$@.2| tee tmp/$@.1
1924

2025
# test2 has the data type in the output
2126
test2:
27+
$(COMMON_VENV) \
28+
$(PIP_INSTALL) -r requirements.txt; \
2229
./test2.py -f testdata/DOMAINS.txt 2>tmp/$@.2 | tee tmp/$@.1
2330

2431
# test3 simulates the whoisdomain command and has no data type in the output
2532
test3:
33+
$(COMMON_VENV) \
34+
$(PIP_INSTALL) -r requirements.txt; \
2635
./test3.py -f testdata/DOMAINS.txt 2>tmp/$@.2 | tee tmp/$@.1
2736

2837
test4:
38+
$(COMMON_VENV) \
39+
$(PIP_INSTALL) -r requirements.txt; \
2940
LOGLEVEL=DEBUG ./test2.py $(TEST_OPTIONS_ALL) -t 2>tmp/$@.2 | tee tmp/$@.1
3041

3142
testwith: withPublicSuffix withExtractServers stripHttpStatus
3243

3344
withPublicSuffix:
45+
$(COMMON_VENV) \
46+
$(PIP_INSTALL) -r requirements.txt; \
3447
./test2.py -d www.dublin.airport.aero --withPublicSuffix
3548

3649
withExtractServers:
50+
$(COMMON_VENV) \
51+
$(PIP_INSTALL) -r requirements.txt; \
3752
./test2.py -d google.com --extractServers
3853

3954
stripHttpStatus:
40-
./test2.py -d nic.aarp --stripHttpStatus
41-
./test2.py -d nic.abudhabi --stripHttpStatus
42-
./test2.py -d META.AU --stripHttpStatus
43-
./test2.py -d google.AU --stripHttpStatus
55+
$(COMMON_VENV) \
56+
$(PIP_INSTALL) -r requirements.txt; \
57+
./test2.py -d nic.aarp --stripHttpStatus;\
58+
./test2.py -d nic.abudhabi --stripHttpStatus; \
59+
./test2.py -d META.AU --stripHttpStatus; \
60+
./test2.py -d google.AU --stripHttpStatus; \

t1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def main() -> None:
4141
"Mu",
4242
"Nirvana",
4343
"Purgatory",
44+
"JustHereOnMyDyingPlanet",
4445
]
4546

4647
restart_after_count: int = 50

whoisdomain/__init__.py

Lines changed: 85 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
from .whoisParser import WhoisParser
5959

6060
log = logging.getLogger(__name__)
61-
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
6261

6362
HAS_REDIS = False
6463
try:
@@ -197,21 +196,31 @@ def q2(
197196
pc: ParameterContext,
198197
) -> Domain | None:
199198
if pc.verbose is True:
200-
os.putenv("LOGLEVEL", "DEBUG")
201-
os.environ["LOGLEVEL"] = "DEBUG"
202199
logging.basicConfig(level="DEBUG")
203200

204201
gc.collect(0)
205202
gc.collect(1)
206203
gc.collect(2)
207204

208-
initLastWhois()
209-
210205
dc = DataContext(
211206
domain=domain,
212207
hasLibTld=TLD_LIB_PRESENT,
213208
)
214209

210+
wr = WhoisRdap()
211+
dd = wr.do_one_domain(domain)
212+
if dd.status:
213+
with_rdap_whois = True
214+
d: dict[str, Any] = wr.map_data_to_whoisdomain(dd.data, with_rdap_whois=with_rdap_whois)
215+
rr = Domain(pc=pc, dc=dc)
216+
rr.from_whodap_dict(d)
217+
msg = f"lookup: {domain} using whodap"
218+
log.info(msg)
219+
return rr # also show the raw data from whodap
220+
log.warning(dd) # no proper answer from rdap try whois
221+
222+
initLastWhois()
223+
215224
dom = Domain(
216225
pc=pc,
217226
dc=dc,
@@ -250,68 +259,90 @@ def q2(
250259
return result
251260

252261

262+
# force: bool = False,
263+
# cache_file: str | None = None,
264+
# cache_age: int = 60 * 60 * 48,
265+
# slow_down: int = 0,
266+
# ignore_returncode: bool = False,
267+
# server: str | None = None,
268+
# verbose: bool = False,
269+
# with_cleanup_results: bool = False,
270+
# internationalized: bool = False,
271+
# include_raw_whois_text: bool = False,
272+
# return_raw_text_for_unsupported_tld: bool = False,
273+
# timeout: float | None = None,
274+
# parse_partial_response: bool = False,
275+
# cmd: str = "whois",
276+
# simplistic: bool = False,
277+
# withRedacted: bool = False,
278+
# tryInstallMissingWhoisOnWindows: bool = False,
279+
# shortResponseLen: int = 5,
280+
# withPublicSuffix: bool = False,
281+
# extractServers: bool = False,
282+
# stripHttpStatus: bool = False,
283+
# noIgnoreWww: bool = False,
284+
285+
253286
def query(
254287
domain: str,
255288
*,
256-
force: bool = False,
257-
cache_file: str | None = None,
258-
cache_age: int = 60 * 60 * 48,
259-
slow_down: int = 0,
260-
ignore_returncode: bool = False,
261-
server: str | None = None,
262-
verbose: bool = False,
263-
with_cleanup_results: bool = False,
264-
internationalized: bool = False,
265-
include_raw_whois_text: bool = False,
266-
return_raw_text_for_unsupported_tld: bool = False,
267-
timeout: float | None = None,
268-
parse_partial_response: bool = False,
269-
cmd: str = "whois",
270-
simplistic: bool = False,
271-
withRedacted: bool = False,
272289
pc: ParameterContext | None = None,
273-
tryInstallMissingWhoisOnWindows: bool = False,
274-
shortResponseLen: int = 5,
275-
withPublicSuffix: bool = False,
276-
extractServers: bool = False,
277-
stripHttpStatus: bool = False,
278-
noIgnoreWww: bool = False,
279-
# if you use pc as argument all above params (except domain are ignored)
290+
verbose: bool = False,
291+
**kwargs: Any,
292+
# force: bool = False,
293+
# cache_file: str | None = None,
294+
# cache_age: int = 60 * 60 * 48,
295+
# slow_down: int = 0,
296+
# ignore_returncode: bool = False,
297+
# server: str | None = None,
298+
# with_cleanup_results: bool = False,
299+
# internationalized: bool = False,
300+
# include_raw_whois_text: bool = False,
301+
# return_raw_text_for_unsupported_tld: bool = False,
302+
# timeout: float | None = None,
303+
# parse_partial_response: bool = False,
304+
# cmd: str = "whois",
305+
# simplistic: bool = False,
306+
# withRedacted: bool = False,
307+
# tryInstallMissingWhoisOnWindows: bool = False,
308+
# shortResponseLen: int = 5,
309+
# withPublicSuffix: bool = False,
310+
# extractServers: bool = False,
311+
# stripHttpStatus: bool = False,
312+
# noIgnoreWww: bool = False,
280313
) -> Domain | None:
281314
# see documentation about paramaters in parameterContext.py
282315

283316
assert isinstance(domain, str), Exception("`domain` - must be <str>")
284317

285318
if verbose is True:
286-
os.putenv("LOGLEVEL", "DEBUG")
287-
os.environ["LOGLEVEL"] = "DEBUG"
288319
logging.basicConfig(level="DEBUG")
289320

290321
if pc is None:
291-
pc = ParameterContext(
292-
force=force,
293-
cache_file=cache_file,
294-
cache_age=cache_age,
295-
slow_down=slow_down,
296-
ignore_returncode=ignore_returncode,
297-
server=server,
298-
verbose=verbose,
299-
with_cleanup_results=with_cleanup_results,
300-
internationalized=internationalized,
301-
include_raw_whois_text=include_raw_whois_text,
302-
return_raw_text_for_unsupported_tld=return_raw_text_for_unsupported_tld,
303-
timeout=timeout,
304-
parse_partial_response=parse_partial_response,
305-
cmd=cmd,
306-
simplistic=simplistic,
307-
withRedacted=withRedacted,
308-
withPublicSuffix=withPublicSuffix,
309-
shortResponseLen=shortResponseLen,
310-
tryInstallMissingWhoisOnWindows=tryInstallMissingWhoisOnWindows,
311-
extractServers=extractServers,
312-
stripHttpStatus=stripHttpStatus,
313-
noIgnoreWww=noIgnoreWww,
314-
)
322+
pc = ParameterContext(**kwargs)
323+
# force=force,
324+
# cache_file=cache_file,
325+
# cache_age=cache_age,
326+
# slow_down=slow_down,
327+
# ignore_returncode=ignore_returncode,
328+
# server=server,
329+
# verbose=verbose,
330+
# with_cleanup_results=with_cleanup_results,
331+
# internationalized=internationalized,
332+
# include_raw_whois_text=include_raw_whois_text,
333+
# return_raw_text_for_unsupported_tld=return_raw_text_for_unsupported_tld,
334+
# timeout=timeout,
335+
# parse_partial_response=parse_partial_response,
336+
# cmd=cmd,
337+
# simplistic=simplistic,
338+
# withRedacted=withRedacted,
339+
# withPublicSuffix=withPublicSuffix,
340+
# shortResponseLen=shortResponseLen,
341+
# tryInstallMissingWhoisOnWindows=tryInstallMissingWhoisOnWindows,
342+
# extractServers=extractServers,
343+
# stripHttpStatus=stripHttpStatus,
344+
# noIgnoreWww=noIgnoreWww,
345+
# )
315346

316347
msg = f"{pc}"
317348
log.debug(msg)

whoisdomain/cache/dbmCache.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import dbm
22
import logging
3-
import os
43

54
log = logging.getLogger(__name__)
6-
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
75

86

97
class DBMCache:

whoisdomain/cache/dummyCache.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import logging
2-
import os
32

43
log = logging.getLogger(__name__)
5-
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
64

75

86
class DummyCache:

whoisdomain/cache/redisCache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import logging
2-
import os
32

43
log = logging.getLogger(__name__)
5-
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
4+
65

76
HAS_REDIS = False
87
try:

whoisdomain/cache/simpleCacheBase.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import logging
2-
import os
32
import time
43

54
log = logging.getLogger(__name__)
6-
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
75

86

97
class SimpleCacheBase:

whoisdomain/cache/simpleCacheWithFile.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import json
22
import logging
3-
import os
43
import pathlib
54

65
from .simpleCacheBase import (
76
SimpleCacheBase,
87
)
98

109
log = logging.getLogger(__name__)
11-
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
1210

1311

1412
class SimpleCacheWithFile(SimpleCacheBase):

whoisdomain/context/dataContext.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import logging
2-
import os
32
from typing import (
43
Any,
54
)
65

76
log = logging.getLogger(__name__)
8-
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
97

108

119
class DataContext:

0 commit comments

Comments
 (0)