def strtocidr(ips):
"""returns CIDR start + length from string"""
rng = 32
pos = string.find(ips, '/')
if not pos == -1:
rng = string.atoi(ips[pos+1:])
ips = ips[:pos]
if string.find(ips, '.') == -1:
ip = string.atol(ips)
else:
ip = strtoip(ips)
if rng < 0 or rng > 32:
raise ValueError, "CIDR length out of range"
return (ip, rng)
评论列表
文章目录