Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'get_recursive' option for legacy whois to RIPE NCC #295

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add 'get_recursive' option for legacy whois to RIPE NCC
This patch adds an argument `get_recursive` to `lookup_whois()`. The
argument default is True, which causes no change to the behavior. If
the user passes `get_recursive=False`, and the IP is allocated to
RIPE, this causes the `-r` flag to be included in the query string.
The `-r` flag asks RIPE WHOIS servers not to perform recursive
queries, such as for related "person" or "role" objects. This helps
users avoid IP blacklisting by RIPE.

The `-r` flag is only supported by RIPE, so this patch only affects
queries to RIPE servers.
  • Loading branch information
wiki-ST47 committed Nov 6, 2020

Verified

This commit was signed with the committer’s verified signature.
Kwasow Karol Wąsowski
commit 57eb0566759f09165a23bf5d3c581c29ab53033a
8 changes: 6 additions & 2 deletions ipwhois/ipwhois.py
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ def lookup_whois(self, inc_raw=False, retry_count=3, get_referral=False,
extra_blacklist=None, ignore_referral_errors=False,
field_list=None, extra_org_map=None,
inc_nir=True, nir_field_list=None, asn_methods=None,
get_asn_description=True):
get_asn_description=True, get_recursive=True):
"""
The function for retrieving and parsing whois information for an IP
address via port 43 (WHOIS).
@@ -113,6 +113,10 @@ def lookup_whois(self, inc_raw=False, retry_count=3, get_referral=False,
get_asn_description (:obj:`bool`): Whether to run an additional
query when pulling ASN information via dns, in order to get
the ASN description. Defaults to True.
get_recursive (:obj:`bool`): Whether to ask the server to perform
recursive queries to get related objects. If False, passes
the '-r' flag to RIPE WHOIS servers. Has no effect for other
RIRs. Defaults to True.

Returns:
dict: The IP whois lookup results
@@ -167,7 +171,7 @@ def lookup_whois(self, inc_raw=False, retry_count=3, get_referral=False,
inc_raw=inc_raw, retry_count=retry_count, response=None,
get_referral=get_referral, extra_blacklist=extra_blacklist,
ignore_referral_errors=ignore_referral_errors, asn_data=asn_data,
field_list=field_list
field_list=field_list, get_recursive=get_recursive,
)

# Add the WHOIS information to the return dictionary.
5 changes: 3 additions & 2 deletions ipwhois/net.py
Original file line number Diff line number Diff line change
@@ -512,7 +512,7 @@ def get_asn_origin_whois(self, asn_registry='radb', asn=None,
)

def get_whois(self, asn_registry='arin', retry_count=3, server=None,
port=43, extra_blacklist=None):
port=43, extra_blacklist=None, get_recursive=True):
"""
The function for retrieving whois or rwhois information for an IP
address via any port. Defaults to port 43/tcp (WHOIS).
@@ -562,8 +562,9 @@ def get_whois(self, asn_registry='arin', retry_count=3, server=None,
# Prep the query.
query = self.address_str + '\r\n'
if asn_registry == 'arin':

query = 'n + {0}'.format(query)
if asn_registry == 'ripencc' and get_recursive is False:
query = '-r {0}'.format(query)

# Query the whois server, and store the results.
conn.send(query.encode())
4 changes: 2 additions & 2 deletions ipwhois/whois.py
Original file line number Diff line number Diff line change
@@ -550,7 +550,7 @@ def get_nets_other(self, response):
def lookup(self, inc_raw=False, retry_count=3, response=None,
get_referral=False, extra_blacklist=None,
ignore_referral_errors=False, asn_data=None,
field_list=None, is_offline=False):
field_list=None, is_offline=False, get_recursive=True):
"""
The function for retrieving and parsing whois information for an IP
address via port 43/tcp (WHOIS).
@@ -635,7 +635,7 @@ def lookup(self, inc_raw=False, retry_count=3, response=None,
# Retrieve the whois data.
response = self._net.get_whois(
asn_registry=asn_data['asn_registry'], retry_count=retry_count,
extra_blacklist=extra_blacklist
extra_blacklist=extra_blacklist, get_recursive=get_recursive
)

if get_referral: