Skip to main content

Port range with support of CIDR-like notation.

Project description

Port range with support of CIDR-like notation.

Stable release: Last release Python versions Software license Requirements freshness

Development: Unit-tests status Coverage Status Code Quality


Support CIDR-like notation:

>>> from port_range import PortRange
>>> pr = PortRange('1027/15')
>>> pr.port_from
>>> pr.port_to
>>> pr.bounds
(1027, 1028)

Parse and normalize port ranges:

>>> pr = PortRange(' 4242-42 ')
>>> pr.bounds
(42, 4242)
>>> str(pr)

Enforce strong validation in strict mode:

>>> PortRange(' 4242-42 ', strict=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "port_range/", line 62, in __init__
    self.port_from, self.port_to = self.parse(port_range)
  File "port_range/", line 109, in parse
    raise ValueError("Invalid reversed port range.")
ValueError: Invalid reversed port range.

Access to decimal-representation properties:

>>> pr = PortRange('1027/15')
>>> pr.base
>>> pr.prefix
>>> pr.mask
>>> pr.offset


This software is licensed under the BSD 2-Clause License.

Changes for v2.1.0 (2017-08-02)

  • Rename port_lenght property to port_length.

Full changelog.

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
port_range-2.1.0-py2.7.egg (7.3 kB) Copy SHA256 hash SHA256 Egg 2.7 Aug 2, 2017
port_range-2.1.0-py2.py3-none-any.whl (9.8 kB) Copy SHA256 hash SHA256 Wheel 2.7 Aug 2, 2017
port-range-2.1.0.tar.gz (9.4 kB) Copy SHA256 hash SHA256 Source None Aug 2, 2017

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 DigiCert DigiCert EV certificate StatusPage StatusPage Status page