Changed asn and ipinfo function output and caching

This commit is contained in:
tke
2023-05-24 12:49:01 +02:00
parent 724378945c
commit 8a316e7b16

View File

@@ -185,12 +185,13 @@ def _asn(ip):
res['name']=" ".join(name_split[:-1]) res['name']=" ".join(name_split[:-1])
return res return res
@disk_cache_decorator() @functools.lru_cache(maxsize=1000)
def asn(ip, type="asn"): def asn(ip, type="asn"):
if len(ip.split(",")) > 1: if len(ip.split(",")) > 1:
return ",".join([_asn(x, type) for x in ip.split(",")]) return ",".join([_asn(x, type) for x in ip.split(",")])
try: try:
return _asn(ip)[type] record = _asn(ip)
return f'({record["asn"]}:{record["name"]}[{record["country"]}]'
except: except:
return "" return ""
@@ -206,12 +207,15 @@ def _ipinfo(ip):
except ModuleNotFoundError: except ModuleNotFoundError:
return None return None
@functools.lru_cache(maxsize=1000)
def ipinfo(ip, type="country"): def ipinfo(ip, type="country"):
if len(ip.split(",")) > 1: if len(ip.split(",")) > 1:
return ",".join([ipinfo(x, type) for x in ip.split(",")]) return ",".join([ipinfo(x, type) for x in ip.split(",")])
try: try:
return _ipinfo(ip)[type] if type:
return _ipinfo(ip)[type]
else:
return _ipinfo(ip)
except: except:
return "" return ""
@@ -225,6 +229,7 @@ def split_number2ip(number):
else: else:
return number return number
@functools.lru_cache(maxsize=1000)
def mx_lookup(domain): def mx_lookup(domain):
domain = domain.lstrip("www.") domain = domain.lstrip("www.")
try: try: