block_len -= cur_len
netlen = largest_prefix(block_len + 1, max_netlen, msb_mask)
return res
-
-# test driver
-if __name__ == "__main__":
- import sys
- a = new("127.00.000.1/24")
- b = new("127.0.0.1", 32)
- c = new("24.232.119.192", 26)
- d = new("24.232.119.0", 24)
- e = new("24.224.0.0", 11)
- f = new("216.168.111.0/27");
- g = new("127.0.0.2/31");
- h = new("127.0.0.16/32")
- i = new("3ffe:4:201e:beef::0/64");
- j = new("2001:3c01::/32")
-
- print f.addr
- print j.addr
-
- try:
- bad = new("24.261.119.0", 32)
- except ValueError, x:
- print "error:", x
-
- print "cidr:", a, "num addresses:", a.length(), "ending address", \
- a.end(), "netmask", a.netmask()
-
- print "cidr:", j, "num addresses:", j.length(), "ending address", \
- j.end(), "netmask", j.netmask()
-
- clist = [a, b, c, d, e, f, g, h, i , j]
- print "unsorted list of cidr objects:\n ", clist
-
-
- clist.sort()
- print "sorted list of cidr object:\n ", clist
-
- k = new("2001:3c01::1:0", 120)
- print "supernet: ", str(j), " supernet of ", str(k), "? ", \
- str(j.is_supernet(k))
- print "supernet: ", str(k), " supernet of ", str(j), "? ", \
- str(k.is_supernet(j))
- print "subnet: ", str(j), " subnet of ", str(k), "? ", \
- str(j.is_subnet(k))
- print "subnet: ", str(k), " subnet of ", str(j), "? ", \
- str(k.is_subnet(j))
-
- netblocks = [ ("192.168.10.0", "192.168.10.255"),
- ("192.168.10.0", "192.168.10.63"),
- ("172.16.0.0", "172.16.127.255"),
- ("24.33.41.22", "24.33.41.37"),
- ("196.11.1.0", "196.11.30.255"),
- ("192.247.1.0", "192.247.10.255"),
- ("10.131.43.3", "10.131.44.7"),
- ("3ffe:4:5::", "3ffe:4:5::ffff"),
- ("3ffe:4:5::", "3ffe:4:6::1")]
-
- for start, end in netblocks:
- print "netblock %s - %s:" % (start, end)
- blocks = netblock_to_cidr(start, end)
- print blocks