Package netaddr :: Module misc
[frames] | no frames]

Source Code for Module netaddr.misc

 1  #!/usr/bin/env python 
 2  #----------------------------------------------------------------------------- 
 3  #   Copyright (c) 2008, David P. D. Moss. All rights reserved. 
 4  # 
 5  #   Released under the BSD license. See the LICENSE file for details. 
 6  #----------------------------------------------------------------------------- 
 7  """ 
 8  Miscellanous functions and classes. Do not rely on anything in here as it is 
 9  liable to change, move or be deleted with each release. 
10  """ 
11  import pprint 
12   
13  from netaddr import CIDR, Wildcard 
14   
15  #----------------------------------------------------------------------------- 
16 -def ipv4_cidr_prefixes():
17 """ 18 Returns a recordset (list of dicts) of host/network breakdown for IPv4 19 using all of the various CIDR prefixes. 20 """ 21 table = [] 22 prefix = 32 23 while prefix >= 0: 24 cidr = CIDR('0.0.0.0/%d' % prefix) 25 table.append(dict(prefix=str(cidr), hosts=cidr.size(), 26 networks=2 ** cidr.prefixlen)) 27 prefix -= 1 28 return table
29 30 #-----------------------------------------------------------------------------
31 -def ipv6_cidr_prefixes():
32 """ 33 Returns a recordset (list of dicts) of host/network breakdown for IPv6 34 using all of the various CIDR prefixes. 35 """ 36 table = [] 37 prefix = 128 38 while prefix >= 0: 39 cidr = CIDR('::/%d' % prefix) 40 table.append(dict(prefix=str(cidr), hosts=cidr.size(), 41 networks=2 ** cidr.prefixlen)) 42 prefix -= 1 43 return table
44 45 #----------------------------------------------------------------------------- 55 56 #----------------------------------------------------------------------------- 66 67 #----------------------------------------------------------------------------- 68 if __name__ == '__main__': 69 import pprint 70 #pprint.pprint(ipv4_cidr_prefixes()) 71 print_ipv4_cidr_prefixes() 72 #pprint.pprint(ipv6_cidr_prefixes()) 73 print_ipv6_cidr_prefixes() 74