Skip to main content

Cidrize parses IPv4/IPv6 addresses, CIDRs, ranges, and wildcard matches & attempts return a valid list of IP addresses

Project description


Intelligently parse IPv4/IPv6 addresses, CIDRs, ranges, and wildcard matches to attempt return a valid list of IP addresses.

The cidrize() function does all the work trying to parse IP addresses correctly.

Supported input formats

Input is very flexible and can be of any of the following formats:[0-5]

Hyphenated ranges do not need to form a CIDR block but the starting number must be of lower value than the end. The netaddr module does most of the heavy lifting for us here.

Unsupported formats

Network mask (e.g. and host mask (aka reverse mask, notation are not accepted at this time.

The cidrize function returns a list of consolidated netaddr.IPNetwork objects. By default parsing exceptions will raise a CidrizeError (with default argument of modular=True). You may pass modular=False to cause exceptions to be stripped and the error text will be returned as a list. This is intended for use with scripts or APIs where receiving exceptions would not be preferred.

The module may also be run as a script for debugging purposes.


:netaddr: Pythonic manipulation of IPv4, IPv6, CIDR, EUI and MAC network addresses


Fire up your trusty old Python interpreter and follow along!

>>> from cidrize import cidrize

Old-fashioned CIDR

>>> cidrize("")

Hyphenated range (default, strict=False)

>>> cidrize("")

Hyphenated range strict (strict=True)

>>> cidrize("", strict=True)
[IPNetwork(''), IPNetwork(''),
IPNetwork(''), IPNetwork(''),


You may provide wildcards using asterisks. This is limited to the 4th and final octet only:

>>> cidrize("15.63.148.*")

Bracketed range

>>> cidrize("[40-99]")
[IPNetwork(''), IPNetwork(''),
IPNetwork(''), IPNetwork('')]


Bad CIDR prefixes are rejected outright:

>>> cidrize("")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "", line 145, in cidrize
    raise CidrizeError(err)
cidrize.CidrizeError: CIDR prefix /40 out of range for IPv4!

Wack range?!

Ranges must always start from lower to upper bound, or this happens:

>>> cidrize("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 145, in cidrize
    raise CidrizeError(err)
cidrize.CidrizeError: lower bound IP greater than upper bound!

Cidr Tool

The cidrize package also comes with the cidr command, which has two basic operations.

Simple output:

% cidr

Verbose output:

% cidr -v
Spanning CIDR:
Block Start/Network:
1st host:     
Block End/Broadcast:
DQ Mask:      
Cisco ACL Mask:
# of hosts:             2
Explicit CIDR blocks:

And that’s that!


Cidrize is licensed under the BSD 3-Clause License. Please see LICENSE.rst for the details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
cidrize-0.6.4.tar.gz (11.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page