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

Fix unable to do rdap lookup #437

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Changes from all commits
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
13 changes: 8 additions & 5 deletions modules/ip_info/asn_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ def get_asn_info_from_geolite(self, ip) -> dict:

return ip_info

def cache_ip_range(self, ip):
def cache_ip_range(self, ip: str):
"""
Get the range of the given ip and
cache the asn of the whole ip range
"""
if not ip:
return False

try:
# Cache the range of this ip
whois_info = ipwhois.IPWhois(address=ip).lookup_rdap()
whois_info: dict = ipwhois.IPWhois(address=ip).lookup_rdap()
asnorg = whois_info.get('asn_description', False)
asn_cidr = whois_info.get('asn_cidr', False)
asn_number = whois_info.get('asn', False)
Expand All @@ -115,12 +118,12 @@ def cache_ip_range(self, ip):
except (
ipwhois.exceptions.IPDefinedError,
ipwhois.exceptions.HTTPLookupError,
ipwhois.exceptions.ASNRegistryError,
ipwhois.exceptions.ASNParseError,
):
# private ip or RDAP lookup failed. don't cache
# or ASN lookup failed with no more methods to try
return False
except ipwhois.exceptions.ASNRegistryError:
# ASN lookup failed with no more methods to try
pass


def get_asn_online(self, ip):
Expand Down
Loading