Port range with support of CIDR-like notation.
Project description
Like Python’s standard library ipaddress package, but for ports.
Features
Support CIDR-like notation:
>>> from port_range import PortRange
>>> pr = PortRange('1027/15')
>>> pr.port_from
1027
>>> pr.port_to
1028
>>> pr.bounds
(1027, 1028)
Parse and normalize port ranges:
>>> pr = PortRange(' 4242-42 ')
>>> pr.bounds
(42, 4242)
>>> str(pr)
'42-4242'
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/__init__.py", line 62, in __init__
self.port_from, self.port_to = self.parse(port_range)
File "port_range/__init__.py", 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
1027
>>> pr.prefix
15
>>> pr.mask
1
>>> pr.offset
3
License
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file port-range-2.2.0.tar.gz.
File metadata
- Download URL: port-range-2.2.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f82644e3a2597ad24dcb8bb29688d7af042b4b83f8f476640eb726f30d6ef21
|
|
| MD5 |
3627ce51876522c2a39bff5b08d09a01
|
|
| BLAKE2b-256 |
ea3b7ffc718e1555b98d7ba2b22e63435f40f041050d60918b16107d3cb2e377
|
File details
Details for the file port_range-2.2.0-py3.7.egg.
File metadata
- Download URL: port_range-2.2.0-py3.7.egg
- Upload date:
- Size: 13.7 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07731cfd49f366bd2b39ec84db60daf6fc2da0b30a9bc5fc4d7737dc8c3f6f38
|
|
| MD5 |
dfda31f2f24c2b96066c2f7b55558b4d
|
|
| BLAKE2b-256 |
9d5657f20245c1a2d37d8d126c01b422abd8243a57de88978328cd4733c17340
|
File details
Details for the file port_range-2.2.0-py2.py3-none-any.whl.
File metadata
- Download URL: port_range-2.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
872f97b8086e3eb790cc2a3162b429d58d51d5e96f180d42ac0188def1964086
|
|
| MD5 |
e87afdb4260febe8734324ef93692168
|
|
| BLAKE2b-256 |
4591455c904ed8cf8d8118dc113bb9e88beedbbde7967fd9f9587b0af6f2aab8
|