def convert(self, net):
parts = net.split('/')
if len(parts) != 2:
return (-1, -1)
ip_s, mask_s = parts[0], parts[1]
if ip_s and mask_s:
try:
ip = struct.unpack('>I', socket.inet_aton(ip_s))[0]
except socket.error:
return (-1, -1)
mask = int(mask_s)
if mask < 0 or mask > 32:
return (-1, -1)
hex_mask = 0xffffffff - (1 << (32 - mask)) + 1
lowest = ip & hex_mask
highest = lowest + (1 << (32 - mask)) - 1
return (lowest, highest)
评论列表
文章目录