To use this package in your project, install and do the following:

>>> from netcidr import CIDR, Networks
>>> CIDR('172.16.4.28/27')
172.16.4.28/27

There are extensive doctests in the library -- please look at those for
many, many examples of usage.

For convenience, a few small examples are presented below:

    # create CIDR addresses for hosts and net blocks:
    >>> from netcidr import CIDR, Networks
    >>> CIDR('10.4.1.2')
    10.4.1.2
    >>> CIDR('10.4.1.x')
    10.4.1.0/24
    >>> CIDR('10.*.*.*')
    10.0.0.0/8
    >>> c = CIDR('172.16.4.28/27')
    >>> c
    172.16.4.28/27
    >>> c.getHostCount()
    32

    # get ranges of addresses for net blocks:
    >>> CIDR('172.16.4.27/31').getHostRange()
    (172.16.4.26, 172.16.4.27)
    >>> CIDR('172.16.4.27/21').getHostRange()
    (172.16.0.0, 172.16.7.255)
    >>> CIDR('172.16.4.27/3').getHostRange()
    (160.0.0.0, 191.255.255.255)

    # create collections of networks:
    >>> net_cidr = CIDR('192.168.4.0/24')
    >>> corp_cidr = CIDR('10.5.0.0/16')
    >>> vpn_cidr = CIDR('172.16.9.5/27')
    >>> mynets = Networks([net_cidr, corp_cidr, vpn_cidr])

    # determine if a CIDR address is in a given network or set of networks:
    >>> home_router = CIDR('192.168.4.1')
    >>> laptop1 = CIDR('192.168.4.100')
    >>> webserver = CIDR('10.5.10.10')
    >>> laptop2 = CIDR('172.16.9.17')
    >>> google = CIDR('64.233.187.99')
    >>> home_router in mynets
    True
    >>> laptop1 in mynets
    True
    >>> webserver in mynets
    True
    >>> laptop2 in mynets
    True
    >>> google in mynets
    False

    # three different exmaples of how to build a collection of networks
    # spanning an arbitrary range of IP addresses:
    >>> start = '172.31.0.0'
    >>> end = '172.31.0.10'
    >>> nets = Networks()
    >>> nets.assembleBlocks(start, end)
    >>> for net in nets:
    ...   net, net.getHostRange()
    (172.31.0.0/29, (172.31.0.0, 172.31.0.7))
    (172.31.0.8/31, (172.31.0.8, 172.31.0.9))
    (172.31.0.10, (172.31.0.10, 172.31.0.10))

    >>> start = '10.0.7.0'
    >>> end = '10.0.10.1'
    >>> nets = Networks()
    >>> nets.assembleBlocks(start, end)
    >>> for net in nets:
    ...   net, net.getHostRange()
    (10.0.7.0/24, (10.0.7.0, 10.0.7.255))
    (10.0.8.0/23, (10.0.8.0, 10.0.9.255))
    (10.0.10.0/31, (10.0.10.0, 10.0.10.1))

    >>> start = '192.168.4.4'
    >>> end = '192.168.4.53'
    >>> nets = Networks()
    >>> nets.assembleBlocks(start, end)
    >>> for net in nets:
    ...   net, net.getHostRange()
    (192.168.4.4/30, (192.168.4.4, 192.168.4.7))
    (192.168.4.8/29, (192.168.4.8, 192.168.4.15))
    (192.168.4.16/28, (192.168.4.16, 192.168.4.31))
    (192.168.4.32/28, (192.168.4.32, 192.168.4.47))
    (192.168.4.48/30, (192.168.4.48, 192.168.4.51))
    (192.168.4.52/31, (192.168.4.52, 192.168.4.53))

    # build a collection of networks that include only the IP addresses that
    # are given (excluding 192.168.4.111)::
    >>> ips = ['192.168.4.%s' % x for x in xrange(0,256) if x != 111]
    >>> nets = Networks()
    >>> nets.fromIPs(ips)
    >>> for net in nets:
    ...   print net
    192.168.4.0/26
    192.168.4.64/27
    192.168.4.96/29
    192.168.4.104/30
    192.168.4.108/31
    192.168.4.110
    192.168.4.112/28
    192.168.4.128/25

    # or conversely, build a collection of networks begining with startIP but
    # that do not include the given IP addresses:
    >>> startIP = '192.168.4.0'
    >>> endIP = '192.168.4.255'
    >>> exclude = ['192.168.4.111']
    >>> nets = Networks()
    >>> nets.withoutIPs(startIP, endIP, exclude)
    >>> for net in nets:
    ...   print net
    192.168.4.0/26
    192.168.4.64/27
    192.168.4.96/29
    192.168.4.104/30
    192.168.4.108/31
    192.168.4.110
    192.168.4.112/28
    192.168.4.128/25


