From 9961fcabeeedc4d40e75fe316c5a8c851ddfd839 Mon Sep 17 00:00:00 2001 From: meeb Date: Sat, 20 Apr 2024 16:07:27 +1000 Subject: [PATCH] follow related and registration links in RDAP data to query child RDAP servers which will have more information, resolves #26 --- whoisit/__init__.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/whoisit/__init__.py b/whoisit/__init__.py index 3d6f3d1..a8fdb07 100644 --- a/whoisit/__init__.py +++ b/whoisit/__init__.py @@ -44,8 +44,24 @@ def domain(domain_name, raw=False, allow_insecure_ssl=False, session=None): query_type='domain', query_value=domain_name) q = Query(session, method, url) response = q.request() - return response if raw else parse(_bootstrap, 'domain', domain_name, response) - + if raw: + return response + # Attempt to follow the 'related' or 'registration' links if the TLD has + # an upstream RDAP endpoint that may have more information + relresponse = None + for link in response.get('links', []): + rel = link.get('rel', '') + if rel in ('related', 'registration'): + relhref = link.get('href', '') + if relhref: + print(f'MAKING SUBREQUEST TO {relhref}') + relq = Query(session, method, relhref) + relresponse = relq.request() + break + if relresponse: + return parse(_bootstrap, 'domain', domain_name, relresponse) + else: + return parse(_bootstrap, 'domain', domain_name, response) def ip(ip_address_or_network, rir=None, raw=False, allow_insecure_ssl=False, session=None): session = get_session(session, allow_insecure_ssl=allow_insecure_ssl)