pcap-to-data-flow.py 文件源码

python
阅读 41 收藏 0 点赞 0 评论 0

项目:data-flow-graph 作者: macbre 项目源码 文件源码
def normalize_host(ip):
    def resolve_host(ip):
        logger = logging.getLogger('resolve_host')

        try:
            hostname = gethostbyaddr(ip)[0]
        except herror as e:
            # socket.herror: [Errno 1] Unknown host
            logger.error("Unable to resolve %s: %s", ip, e)
            return ip

        hostname = hostname.split('.')[0]
        logger.info("%s is known as %s", ip, hostname)

        if not hostname.startswith('ap-'):
            return hostname
        else:
            # ap-s200 -> ap-s*
            return re.sub(r'\d+$', '*', hostname)

    if ip not in hosts_cache:
        hosts_cache[ip] = resolve_host(ip)

    return hosts_cache[ip]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号