1
2
3
4
5
6
7 """
8 Miscellaneous 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
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
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
47 """
48 Prints a table to stdout of host/network breakdown for IPv4 using CIDR
49 notation.
50 """
51 print '%-10s %-15s %-15s' % ('Prefix', 'Hosts', 'Networks')
52 print '-'*10, '-'*15, '-'*15
53 for record in ipv4_cidr_prefixes():
54 print '%(prefix)-10s %(hosts)15s %(networks)15s' % record
55
56
58 """
59 Prints a table to stdout of host/network breakdown for IPv6 using CIDR
60 notation.
61 """
62 print '%-10s %-40s %-40s' % ('Prefix', 'Hosts', 'Networks')
63 print '-'*10, '-'*40, '-'*40
64 for record in ipv6_cidr_prefixes():
65 print '%(prefix)-10s %(hosts)40s %(networks)40s' % record
66
67
68 if __name__ == '__main__':
69 import pprint
70
71 print_ipv4_cidr_prefixes()
72
73 print_ipv6_cidr_prefixes()
74