Changed asn and ipinfo function output and caching
This commit is contained in:
@@ -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:
|
||||||
|
if type:
|
||||||
return _ipinfo(ip)[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:
|
||||||
|
|||||||
Reference in New Issue
Block a user