Skip to main content

Port range with support of CIDR-like notation.

Project description

Like Python’s standard library ipaddress package, but for ports.

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.2.0 (2019-09-19)

  • Fix Travis build
  • Implement equality and hash operators
  • Fix deprecated collections warning

Full changelog.

Project details

Download files

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

Files for port-range, version 2.2.0
Filename, size File type Python version Upload date Hashes
Filename, size port_range-2.2.0-py2.py3-none-any.whl (8.8 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size port_range-2.2.0-py3.7.egg (13.7 kB) File type Egg Python version 3.7 Upload date Hashes View
Filename, size port-range-2.2.0.tar.gz (9.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page