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
评论列表
文章目录