netmon.py 文件源码

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

项目:netmon 作者: bullerian 项目源码 文件源码
def _ipnet(net_str):
        """
        This function is used for argparse module to verify validness of
        entered network. Valid networks are IPv4 networks in form
        A.B.C.D/prefix
        :param net_str: string that represents IPv4 net. Example A.B.C.D/prefix.
        :return: ipaddress.ip_network object or raises exception on fail
        """
        try:
            the_net = ipaddress.ip_network(net_str)
        except ValueError:
            msg = '{} is not a valid IP network address'.format(net_str)
            raise argparse.ArgumentTypeError(msg)

        if the_net.version != Utilities.IPV4:
            msg = 'Only IPv4 addresses are supported'
            raise argparse.ArgumentTypeError(msg)

        return the_net
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号