def get_ip_network(ip_str):
"""
Try to return the owner of the IP address (based on ips.py)
:param str ip_str: The IP address
:rtype: str
:return: The owner if find else None
"""
try:
ip_addr = netaddr.IPAddress(ip_str)
except (netaddr.AddrConversionError, netaddr.AddrFormatError):
return None
for brand, networks in IPS_NETWORKS.iteritems():
for net in networks:
if net.netmask.value & ip_addr.value == net.value:
return brand
return None
评论列表
文章目录