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