netports


Namenetports JSON
Version 0.12.0 PyPI version JSON
download
home_pagehttps://github.com/vladimirs-git/netports
SummaryPython tools for managing ranges of VLANs, TCP/UDP ports, IP protocols, Interfaces
upload_time2023-12-05 13:37:22
maintainer
docs_urlNone
authorVladimirs Prusakovs
requires_python>=3.8,<4.0
licenseApache-2.0
keywords networking port range tcp udp vlan ip
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
.. image:: https://img.shields.io/pypi/v/netports.svg
   :target: https://pypi.python.org/pypi/netports
.. image:: https://img.shields.io/pypi/pyversions/netports.svg
   :target: https://pypi.python.org/pypi/netports


netports
========

Python tools for managing ranges of VLANs, TCP/UDP ports, IP protocols, Interfaces
Recommended for scripting in telecommunications networks.


Requirements
------------

Python >=3.8


Installation
------------

Install the package from pypi.org release

.. code:: bash

    pip install netports

or install the package from github.com release

.. code:: bash

    pip install https://github.com/vladimirs-git/netports/archive/refs/tags/0.12.0.tar.gz

or install the package from github.com repository

.. code:: bash

    pip install git+https://github.com/vladimirs-git/netports@0.12.0


.. contents:: **Contents**
    :local:


TCP/UDP ports
-------------

check_port()
............
**check_port(port, strict)**
Check TCP/UDP port in the range 1 to 65535.

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
port            *int*                       The TCP/UDP port that needs to be checked.
strict          *bool*                      True - raise NetportsValueError if the port is invalid, False - return False if the port is invalid. Default is `False`.
=============== =========================== ============================================================================

Return
    *bool* True - If the port is in the valid range of 1 to 65535, False - otherwise.
Raises
    *TypeError* If the port is not integer.
    *NetportsValueError* If strict=True and the port is outside the valid range.


check_port()
............
**check_ports(ports, strict)**
heck TCP/UDP ports in the range 1 to 65535.

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
ports           *List[int]*                 The TCP/UDP ports that needs to be checked
strict          *bool*                      True - raise NetportsValueError if any in the ports is invalid, False - return False if the port is invalid. Default is `False`.
=============== =========================== ============================================================================

Return
    *bool* True - if all ports is in the valid range of 1 to 65535, False - otherwise.
Raises
    *TypeError* If any in the ports is not integer.
    *NetportsValueError* If strict=True and any in the ports is outside the valid range.


itcp()
......
**itcp(items, verbose, all)**
Integer TCP/UDP Ports. Sorting TCP/UDP ports and removing duplicates

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of TCP/UDP ports, can be unsorted and with duplicates
verbose         *bool*                      True - all ports in verbose mode: [1, 2, ..., 65535], False - all ports in brief mode: [-1], to save RAM (default)
all             *bool*                      True - Returns all TCP/UDP ports: [1, 2, ..., 65535], or [-1] for verbose=False
=============== =========================== ============================================================================

Return
    *List[int]* of unique sorted TCP/UDP ports
Raises
    *NetportsValueError* if TCP/UDP ports are outside valid range 1...65535



stcp()
......
**stcp(items, verbose, all)**
String TCP/UDP ports. Sorting TCP/UDP ports and removing duplicates

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of TCP/UDP ports, can be unsorted and with duplicates
verbose         *bool*                      True - all ports in verbose mode: [1, 2, ..., 65535], False - all ports in brief mode: [-1], to save RAM (default)
all             *bool*                      True - Returns all TCP/UDP ports: "1-65535"
=============== =========================== ============================================================================

Return
    *str* of unique sorted TCP/UDP ports
Raises
    *NetportsValueError* if TCP/UDP ports are outside valid range 1...65535


**Examples**

`./examples/tcp_udp.py`_



VLAN IDs
--------


ivlan()
.......
**ivlan(items, verbose, all, splitter, range_splitter, platform)**
Sorting integer VLAN IDs and removing duplicates

=============== =========================== ============================================================================
Parameter        Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of VLANs, can be unsorted and with duplicates
verbose         *bool*                      True - all VLAN IDs in verbose mode: [1, 2, ..., 65535], False - all VLAN IDs in brief mode: [-1], to save RAM (default)
all             *bool*                      True - Returns all VLAN IDs: [1, 2, ..., 4094], or [-1] for verbose=False
splitter        *str*                       Separator character between items, by default ","
range_splitter  *str*                       Separator between min and max numbers in range, by default "-"
platform        *str*                       Set ``splitter`` and ``range_splitter`` to platform specific values. Defined: "cisco" (Cisco IOS), "hpe" (Hewlett Packard Enterprise).
=============== =========================== ============================================================================

Return
    *List[int]* of unique sorted VLANs
Raises
    *NetportsValueError* if VLANs are outside valid range 1...4094


svlan()
.......
**svlan(items, verbose, all, splitter, range_splitter, platform)**
Sorting string VLANs and removing duplicates

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of VLANs, can be unsorted and with duplicates
verbose         *bool*                      True - all VLAN IDs in verbose mode: [1, 2, ..., 65535], False - all VLAN IDs in brief mode: [-1], to save RAM (default)
all             *bool*                      True - Returns all VLAN IDs: "1-4094"
splitter        *str*                       Separator character between items, by default ","
range_splitter  *str*                       Separator between min and max numbers in range, by default "-"
platform        *str*                       Set ``splitter`` and ``range_splitter`` to platform specific values. Defined: "cisco" (Cisco IOS), "hpe" (Hewlett Packard Enterprise).
=============== =========================== ============================================================================

Return
    *str* of unique sorted VLANs
Raises
    *NetportsValueError* if VLANs are outside valid range 1...4094


**Examples**

`./examples/vlan.py`_



IP protocols
------------


IP_NAMES, IP_NUMBERS
....................

Dictionary with known IP protocol names and IDs listed in https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers


iip()
.....
**iip(items, verbose, all, strict)**
Sorting IP protocol numbers and removing duplicates


=============== =========================== ============================================================================
Parameter        Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of IP protocol numbers, can be unsorted and with duplicates, "ip" - Return all IP protocol numbers: [0, 1, ..., 255]
verbose         *bool*                      True - all protocols in verbose mode: [0, 1, ..., 255], False - all protocols in brief mode: [-1], to save RAM (default)
strict          *bool*                      True - Raises NetportsValueError, if the protocol is unknown (default), False - Skips unknown protocols
all             *bool*                      True - Return all IP protocol numbers: [0, 1, ..., 255]
=============== =========================== ============================================================================

Return
    *List[int]* of unique sorted IP protocol numbers
Raises
    *NetportsValueError* if IP protocol numbers are outside valid range 0...255

sip()
.....
**sip(items, verbose, all)**
Soring string IP protocol numbers and removing duplicates

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of IP protocol numbers, can be unsorted and with duplicates. "ip" - mean all numbers in range 0...255.
verbose         *bool*                      True - all protocols in verbose mode: [0, 1, ..., 255], False - all protocols in brief mode: [-1], to save RAM (default)
strict          *bool*                      True - Raises NetportsValueError, if the protocol is unknown (default), False - Skips unknown protocols
all             *bool*                      True - Return all IP protocol numbers: "0-255"
=============== =========================== ============================================================================

Return
    *str* of unique sorted IP protocol numbers
Raises
    *NetportsValueError* if IP protocol numbers are outside valid range 0...255


ip_pairs()
..........
**ip_pairs(items, strict)**
Splits items to IP protocol Number, Name and undefined-invalid protocols

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of IP protocol names and numbers, can be unsorted and with duplicates
verbose         *bool*                      True - all protocols in verbose mode: [0, 1, ..., 255], False - all protocols in brief mode: [-1], to save RAM (default)
=============== =========================== ============================================================================

Return
    *List[Tuple[int, str]]* Pairs of IP protocol number and name,
     *List[str]* Undefined protocol names and invalid numbers


**Examples**

`./examples/ip.py`_



Objects
-------

Range()
.......
**Range(items, splitter, range_splitter, strict)**
An object that represents ports range as *str* and as *List[int]*
Object implements most of the `set <https://www.w3schools.com/python/python_ref_set.asp>`_ and
`list <https://www.w3schools.com/python/python_ref_list.asp>`_ methods that handle the Range.numbers attribute.

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
items           *str*, *List[int]*          Range of numbers. Numbers can be unsorted and duplicated.
splitter        *str*                       Separator character between items, by default ","
range_splitter  *str*                       Separator between min and max numbers in range, by default "-"
strict          *bool*                      True - Raise NetportsValueError, if in items is invalid item. False - Make Range without invalid items. By default True.
=============== =========================== ============================================================================

Attributes demonstration


Range operators
:::::::::::::::

**Range** object implements:

- Arithmetic operators: ``+``, ``-``
- Reference to numbers in range by index

=============================== =========================== ============================================================
Operator                        Return                      Description
=============================== =========================== ============================================================
Range("1,4") + Range("3,5")     Range("1,3-5")              Add two objects
Range("1-5") - Range("2")       Range("1,3-5")              Subtract two objects
Range("1,3-5")[1]               3                           Get number by index
Range("1,3-5")[1:3]             [3, 4]                      Get numbers by slice
=============================== =========================== ============================================================


Range methods
:::::::::::::

**Range** object implements most of `set <https://www.w3schools.com/python/python_ref_set.asp>`_
and `list <https://www.w3schools.com/python/python_ref_list.asp>`_ methods.

=================================== ====================================================================================
Method                              Description
=================================== ====================================================================================
add(other)                          Adds other *Range* object to self
append(number)                      Appends number to self
clear()                             Removes all numbers from self
copy()                              Returns a copy of self *Range* object
difference(other)                   Returns the *Range* object of the difference between self and other *Range*
difference_update(other)            Removes other *Range* from self
discard(number)                     Removes the specified number from self *Range*
extend(numbers)                     Adds *List[int]* numbers to self
index(number)                       Returns index of number, raises ValueError if the number is not present in range
intersection(other)                 Returns *Range* which is the intersection of self and other *Range*
intersection_update(other)          Removes numbers of other *Range* in self, that are not present in other
isdisjoint(other)                   Returns whether self numbers and other *Range* numbers have intersection or not
issubset(other)                     Returns whether other *Range* numbers contains self numbers or not
issuperset(other)                   Returns whether self *Range* numbers contains other *Range* numbers set or not
pop()                               Removes and returns last number in *Range*, raises IndexError if list is empty or index is out of range
remove(number)                      Removes the specified number from self *Range*, raises ValueError if the numbers is not present
symmetric_difference(other)         Returns *Range* object with the symmetric differences of self and other *Range*
symmetric_difference_update(other)  Inserts the symmetric differences from self *Range* and other *Range*
update(other)                       Returns *Range* of the union of self *Range* and other *Range*
=================================== ====================================================================================


**Examples**

- Attributes demonstration
- Sorts numbers and removes duplicates
- Range with custom splitters

`./examples/range.py`_



Numbers
-------

parse_range()
.............
**parse_range(line, splitter, range_splitter)**
Parses range from line. Removes white spaces considering splitters.
Sort numbers and removes duplicates.

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
line            *str*                       Range of numbers, can be unsorted and with duplicates
splitter        *str*                       Separator character between items, by default ","
range_splitter  *str*                       Separator between min and max numbers in range, by default "-"
=============== =========================== ============================================================================

Return
    Range *object*


inumbers()
..........
**inumbers(items, splitter, range_splitter)**
Sort integer numbers and removes duplicates

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of numbers, can be unsorted and with duplicates
splitter        *str*                       Separator character between items, by default ","
range_splitter  *str*                       Separator between min and max numbers in range, by default "-"
=============== =========================== ============================================================================

Return
    *List[int]* of unique sorted numbers


snumbers()
..........
**snumbers(items, splitter, range_splitter)**
Sort string numbers and removes duplicates

=============== =========================== ============================================================================
Parameter       Type                        Description
=============== =========================== ============================================================================
items           *str, List[int], List[str]* Range of numbers, can be unsorted and with duplicates
splitter        *str*                       Separator character between items, by default ","
range_splitter  *str*                       Separator between min and max numbers in range, by default "-"
=============== =========================== ============================================================================

Return
    *str* of unique sorted numbers


**Examples**

- Sorts numbers and removes duplicates
- Range with custom splitter and range_splitter
- Converts unsorted range to sorted *List[int]* without duplicates
- Converts unsorted range to *List[int]* with custom splitters
- Converts unsorted range to sorted *str* without duplicates
- Converts unsorted range to *str* with custom splitters

`./examples/numbers.py`_


Interfaces
----------

intfrange()
...........
**intfrange(items, fmt)**
Convert interfaces names to shorted range notation

=========== ============ ===========================================================================
Parameter   Type         Description
=========== ============ ===========================================================================
items       *List[str]*  List of interfaces
fmt         *str*        Format option: "long"  - Long names: ["interface Ethernet1/1-3"], "short" - Short names: ["Eth1/1/1-3"]
=========== ============ ===========================================================================

Return
    *List[str]* Interface ranges


long_to_short()
...............
**long_to_short(device_type, key_lower, value_lower)**
Returns Interfaces map long-to-short, device_type specific

=============== =========================== ============================================================================
Parameter        Type                        Description
=============== =========================== ============================================================================
device_type     *str*                       Netmiko device type, increase priority of device_type specific keys. "", "cisco_asr", "cisco_ios", "cisco_nxos", "hp_comware"
key_lower       *bool*                      True - keys lower-case, False - keys upper-case
value_lower     *bool*                      True - values lower-case, False - values upper-case
=============== =========================== ============================================================================

Return
    *Dict[str, str]* Interfaces map


long_to_long()
..............
**long_to_long(device_type, key_lower, value_lower)**
Returns Interfaces map long-to-long, device_type specific

=============== =========================== ============================================================================
Parameter        Type                        Description
=============== =========================== ============================================================================
device_type     *str*                       Netmiko device type, increase priority of device_type specific keys. "", "cisco_asr", "cisco_ios", "cisco_nxos", "hp_comware"
key_lower       *bool*                      True - keys lower-case, False - keys upper-case
value_lower     *bool*                      True - values lower-case, False - values upper-case
=============== =========================== ============================================================================

Return
    *Dict[str, str]* Interfaces map


short_to_long()
...............
**short_to_long(device_type, key_lower, value_lower)**
Returns Interfaces map short-to-long, device_type specific

=============== =========================== ============================================================================
Parameter        Type                        Description
=============== =========================== ============================================================================
device_type     *str*                       Netmiko device type, increase priority of device_type specific keys. "", "cisco_asr", "cisco_ios", "cisco_nxos", "hp_comware"
key_lower       *bool*                      True - keys lower-case, False - keys upper-case
value_lower     *bool*                      True - values lower-case, False - values upper-case
=============== =========================== ============================================================================

Return
    *Dict[str, str]* Interfaces map


short_to_short()
................
**short_to_short(device_type, key_lower, value_lower)**
Returns Interfaces map short-to-short, device_type specific

=============== =========================== ============================================================================
Parameter        Type                        Description
=============== =========================== ============================================================================
device_type     *str*                       Netmiko device type, increase priority of device_type specific keys. "", "cisco_asr", "cisco_ios", "cisco_nxos", "hp_comware"
key_lower       *bool*                      True - keys lower-case, False - keys upper-case
value_lower     *bool*                      True - values lower-case, False - values upper-case
=============== =========================== ============================================================================

Return
    *Dict[str, str]* Interfaces map


Intf()
......
**Intf(line, device_type, splitter)**
An object of interface name, that can contain up to 4 indexes.
Sorts the interfaces by indexes (not by alphabetic).

=============== ======= ============================================================================
Parameter       Type    Description
=============== ======= ============================================================================
line            *str*   Interface name that can contain up to 4 indexes
device_type     *str*   Netmiko device_type (default "")
splitter        *str*   Separator of characters between indexes (default ",./:")
=============== ======= ============================================================================


Attributes
::::::::::

=============== ============ =======================================================================
Attributes      Type         Description
=============== ============ =======================================================================
delimiters                   Interface all delimiters
id0             *str*        Interface name. Line without IDs
id1             *int*        Interface 1st ID
id2             *int*        Interface 2nd ID
id3             *int*        Interface 3rd ID
id4             *int*        Interface 4th ID
ids                          Interface all IDs
line            *str*        Interface line
name            *str*        Interface name with IDs
splitter        *str*        Separator of characters between indexes
device_type     *str*        Netmiko device_type
=============== ============ =======================================================================


last_idx()
..........
**last_idx()**
Index of last ID in interface line


all_names()
...........
**all_names()**
All variants of names: long, short, upper-case, lover-case. Device type specific


name_full()
...........
**name_full()**
Interface long name with IDs and with interface keyword


name_long()
...........
**name_long()**
Interface long name with IDs and without interface keyword


name_short()
............
**name_short(replace)**
Interface short name with IDs, Device type specific

=========== =========================== ============================================================
Parameter   Type                        Description
=========== =========================== ============================================================
replace     *List[Tuple[str, str]]*     Replace the default short name with the first one
                                        that matches in the list of the 'replace' argument.
=========== =========================== ============================================================

Return
    *str* Interface short name.


part_after()
............
**part_after(idx, splitter)**
Interface part after interested ID

=========== ============ ===========================================================================
Parameter   Type         Description
=========== ============ ===========================================================================
idx         *int*        Interface index
splitter    *bool*       True - Include splitter from edge, False - Skip splitter from edge
=========== ============ ===========================================================================

Return
    *str* Part of the interface name after specified interface index


part_before()
.............
**part_before(idx, splitter)**
Interface part before interested ID

=========== ============ ===========================================================================
Parameter   Type         Description
=========== ============ ===========================================================================
idx         *int*        Interface index
splitter    *bool*       True - Include splitter from edge, False - Skip splitter from edge
=========== ============ ===========================================================================

Return
    *str* Part of the interface name before specified interface index


**Examples**

- Attributes demonstration
- Interface with custom splitter between indexes. Splitter is ignored when comparing
- Sorting by indexes
- Grouping interfaces by 3rd index

`./examples/intfs.py`_


SwVersion()
...........
**SwVersion(text)**
Parse the given version string and return *SwVersion* object who can
compare (>, >=, <, <=) software versions of network devices: Cisco, FortiGate, HP, etc.


.. code:: python

    import re
    from netports import SwVersion

    text = "Cisco IOS Software, C2960X Software (C2960X-UNIVERSALK9-M), Version 15.2(4)E10, ..."
    text = re.search(r"Version (\S+),", text)[1]

    version1 = SwVersion(text)  # 15.2(4)E10
    version2 = SwVersion("15.2(4)E11")

    assert version1 < version2
    assert version1 <= version2
    assert not version1 > version2
    assert not version1 >= version2
    print(version1)  # 15.2(4)e10
    print(version2)  # 15.2(4)e11


.. _`./examples/tcp_udp.py` : ./examples/tcp_udp.py
.. _`./examples/vlan.py` : ./examples/vlan.py
.. _`./examples/ip.py` : ./examples/ip.py
.. _`./examples/range.py` : ./examples/range.py
.. _`./examples/numbers.py` : ./examples/numbers.py
.. _`./examples/intfs.py` : ./examples/intfs.py


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vladimirs-git/netports",
    "name": "netports",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "networking,port,range,tcp,udp,vlan,ip",
    "author": "Vladimirs Prusakovs",
    "author_email": "vladimir.prusakovs@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/28/80/626a15e276bf81109ebf522e6508dd7219deede936fdc61a7ccbc419bda1/netports-0.12.0.tar.gz",
    "platform": null,
    "description": "\n.. image:: https://img.shields.io/pypi/v/netports.svg\n   :target: https://pypi.python.org/pypi/netports\n.. image:: https://img.shields.io/pypi/pyversions/netports.svg\n   :target: https://pypi.python.org/pypi/netports\n\n\nnetports\n========\n\nPython tools for managing ranges of VLANs, TCP/UDP ports, IP protocols, Interfaces\nRecommended for scripting in telecommunications networks.\n\n\nRequirements\n------------\n\nPython >=3.8\n\n\nInstallation\n------------\n\nInstall the package from pypi.org release\n\n.. code:: bash\n\n    pip install netports\n\nor install the package from github.com release\n\n.. code:: bash\n\n    pip install https://github.com/vladimirs-git/netports/archive/refs/tags/0.12.0.tar.gz\n\nor install the package from github.com repository\n\n.. code:: bash\n\n    pip install git+https://github.com/vladimirs-git/netports@0.12.0\n\n\n.. contents:: **Contents**\n    :local:\n\n\nTCP/UDP ports\n-------------\n\ncheck_port()\n............\n**check_port(port, strict)**\nCheck TCP/UDP port in the range 1 to 65535.\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nport            *int*                       The TCP/UDP port that needs to be checked.\nstrict          *bool*                      True - raise NetportsValueError if the port is invalid, False - return False if the port is invalid. Default is `False`.\n=============== =========================== ============================================================================\n\nReturn\n    *bool* True - If the port is in the valid range of 1 to 65535, False - otherwise.\nRaises\n    *TypeError* If the port is not integer.\n    *NetportsValueError* If strict=True and the port is outside the valid range.\n\n\ncheck_port()\n............\n**check_ports(ports, strict)**\nheck TCP/UDP ports in the range 1 to 65535.\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nports           *List[int]*                 The TCP/UDP ports that needs to be checked\nstrict          *bool*                      True - raise NetportsValueError if any in the ports is invalid, False - return False if the port is invalid. Default is `False`.\n=============== =========================== ============================================================================\n\nReturn\n    *bool* True - if all ports is in the valid range of 1 to 65535, False - otherwise.\nRaises\n    *TypeError* If any in the ports is not integer.\n    *NetportsValueError* If strict=True and any in the ports is outside the valid range.\n\n\nitcp()\n......\n**itcp(items, verbose, all)**\nInteger TCP/UDP Ports. Sorting TCP/UDP ports and removing duplicates\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of TCP/UDP ports, can be unsorted and with duplicates\nverbose         *bool*                      True - all ports in verbose mode: [1, 2, ..., 65535], False - all ports in brief mode: [-1], to save RAM (default)\nall             *bool*                      True - Returns all TCP/UDP ports: [1, 2, ..., 65535], or [-1] for verbose=False\n=============== =========================== ============================================================================\n\nReturn\n    *List[int]* of unique sorted TCP/UDP ports\nRaises\n    *NetportsValueError* if TCP/UDP ports are outside valid range 1...65535\n\n\n\nstcp()\n......\n**stcp(items, verbose, all)**\nString TCP/UDP ports. Sorting TCP/UDP ports and removing duplicates\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of TCP/UDP ports, can be unsorted and with duplicates\nverbose         *bool*                      True - all ports in verbose mode: [1, 2, ..., 65535], False - all ports in brief mode: [-1], to save RAM (default)\nall             *bool*                      True - Returns all TCP/UDP ports: \"1-65535\"\n=============== =========================== ============================================================================\n\nReturn\n    *str* of unique sorted TCP/UDP ports\nRaises\n    *NetportsValueError* if TCP/UDP ports are outside valid range 1...65535\n\n\n**Examples**\n\n`./examples/tcp_udp.py`_\n\n\n\nVLAN IDs\n--------\n\n\nivlan()\n.......\n**ivlan(items, verbose, all, splitter, range_splitter, platform)**\nSorting integer VLAN IDs and removing duplicates\n\n=============== =========================== ============================================================================\nParameter        Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of VLANs, can be unsorted and with duplicates\nverbose         *bool*                      True - all VLAN IDs in verbose mode: [1, 2, ..., 65535], False - all VLAN IDs in brief mode: [-1], to save RAM (default)\nall             *bool*                      True - Returns all VLAN IDs: [1, 2, ..., 4094], or [-1] for verbose=False\nsplitter        *str*                       Separator character between items, by default \",\"\nrange_splitter  *str*                       Separator between min and max numbers in range, by default \"-\"\nplatform        *str*                       Set ``splitter`` and ``range_splitter`` to platform specific values. Defined: \"cisco\" (Cisco IOS), \"hpe\" (Hewlett Packard Enterprise).\n=============== =========================== ============================================================================\n\nReturn\n    *List[int]* of unique sorted VLANs\nRaises\n    *NetportsValueError* if VLANs are outside valid range 1...4094\n\n\nsvlan()\n.......\n**svlan(items, verbose, all, splitter, range_splitter, platform)**\nSorting string VLANs and removing duplicates\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of VLANs, can be unsorted and with duplicates\nverbose         *bool*                      True - all VLAN IDs in verbose mode: [1, 2, ..., 65535], False - all VLAN IDs in brief mode: [-1], to save RAM (default)\nall             *bool*                      True - Returns all VLAN IDs: \"1-4094\"\nsplitter        *str*                       Separator character between items, by default \",\"\nrange_splitter  *str*                       Separator between min and max numbers in range, by default \"-\"\nplatform        *str*                       Set ``splitter`` and ``range_splitter`` to platform specific values. Defined: \"cisco\" (Cisco IOS), \"hpe\" (Hewlett Packard Enterprise).\n=============== =========================== ============================================================================\n\nReturn\n    *str* of unique sorted VLANs\nRaises\n    *NetportsValueError* if VLANs are outside valid range 1...4094\n\n\n**Examples**\n\n`./examples/vlan.py`_\n\n\n\nIP protocols\n------------\n\n\nIP_NAMES, IP_NUMBERS\n....................\n\nDictionary with known IP protocol names and IDs listed in https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers\n\n\niip()\n.....\n**iip(items, verbose, all, strict)**\nSorting IP protocol numbers and removing duplicates\n\n\n=============== =========================== ============================================================================\nParameter        Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of IP protocol numbers, can be unsorted and with duplicates, \"ip\" - Return all IP protocol numbers: [0, 1, ..., 255]\nverbose         *bool*                      True - all protocols in verbose mode: [0, 1, ..., 255], False - all protocols in brief mode: [-1], to save RAM (default)\nstrict          *bool*                      True - Raises NetportsValueError, if the protocol is unknown (default), False - Skips unknown protocols\nall             *bool*                      True - Return all IP protocol numbers: [0, 1, ..., 255]\n=============== =========================== ============================================================================\n\nReturn\n    *List[int]* of unique sorted IP protocol numbers\nRaises\n    *NetportsValueError* if IP protocol numbers are outside valid range 0...255\n\nsip()\n.....\n**sip(items, verbose, all)**\nSoring string IP protocol numbers and removing duplicates\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of IP protocol numbers, can be unsorted and with duplicates. \"ip\" - mean all numbers in range 0...255.\nverbose         *bool*                      True - all protocols in verbose mode: [0, 1, ..., 255], False - all protocols in brief mode: [-1], to save RAM (default)\nstrict          *bool*                      True - Raises NetportsValueError, if the protocol is unknown (default), False - Skips unknown protocols\nall             *bool*                      True - Return all IP protocol numbers: \"0-255\"\n=============== =========================== ============================================================================\n\nReturn\n    *str* of unique sorted IP protocol numbers\nRaises\n    *NetportsValueError* if IP protocol numbers are outside valid range 0...255\n\n\nip_pairs()\n..........\n**ip_pairs(items, strict)**\nSplits items to IP protocol Number, Name and undefined-invalid protocols\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of IP protocol names and numbers, can be unsorted and with duplicates\nverbose         *bool*                      True - all protocols in verbose mode: [0, 1, ..., 255], False - all protocols in brief mode: [-1], to save RAM (default)\n=============== =========================== ============================================================================\n\nReturn\n    *List[Tuple[int, str]]* Pairs of IP protocol number and name,\n     *List[str]* Undefined protocol names and invalid numbers\n\n\n**Examples**\n\n`./examples/ip.py`_\n\n\n\nObjects\n-------\n\nRange()\n.......\n**Range(items, splitter, range_splitter, strict)**\nAn object that represents ports range as *str* and as *List[int]*\nObject implements most of the `set <https://www.w3schools.com/python/python_ref_set.asp>`_ and\n`list <https://www.w3schools.com/python/python_ref_list.asp>`_ methods that handle the Range.numbers attribute.\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nitems           *str*, *List[int]*          Range of numbers. Numbers can be unsorted and duplicated.\nsplitter        *str*                       Separator character between items, by default \",\"\nrange_splitter  *str*                       Separator between min and max numbers in range, by default \"-\"\nstrict          *bool*                      True - Raise NetportsValueError, if in items is invalid item. False - Make Range without invalid items. By default True.\n=============== =========================== ============================================================================\n\nAttributes demonstration\n\n\nRange operators\n:::::::::::::::\n\n**Range** object implements:\n\n- Arithmetic operators: ``+``, ``-``\n- Reference to numbers in range by index\n\n=============================== =========================== ============================================================\nOperator                        Return                      Description\n=============================== =========================== ============================================================\nRange(\"1,4\") + Range(\"3,5\")     Range(\"1,3-5\")              Add two objects\nRange(\"1-5\") - Range(\"2\")       Range(\"1,3-5\")              Subtract two objects\nRange(\"1,3-5\")[1]               3                           Get number by index\nRange(\"1,3-5\")[1:3]             [3, 4]                      Get numbers by slice\n=============================== =========================== ============================================================\n\n\nRange methods\n:::::::::::::\n\n**Range** object implements most of `set <https://www.w3schools.com/python/python_ref_set.asp>`_\nand `list <https://www.w3schools.com/python/python_ref_list.asp>`_ methods.\n\n=================================== ====================================================================================\nMethod                              Description\n=================================== ====================================================================================\nadd(other)                          Adds other *Range* object to self\nappend(number)                      Appends number to self\nclear()                             Removes all numbers from self\ncopy()                              Returns a copy of self *Range* object\ndifference(other)                   Returns the *Range* object of the difference between self and other *Range*\ndifference_update(other)            Removes other *Range* from self\ndiscard(number)                     Removes the specified number from self *Range*\nextend(numbers)                     Adds *List[int]* numbers to self\nindex(number)                       Returns index of number, raises ValueError if the number is not present in range\nintersection(other)                 Returns *Range* which is the intersection of self and other *Range*\nintersection_update(other)          Removes numbers of other *Range* in self, that are not present in other\nisdisjoint(other)                   Returns whether self numbers and other *Range* numbers have intersection or not\nissubset(other)                     Returns whether other *Range* numbers contains self numbers or not\nissuperset(other)                   Returns whether self *Range* numbers contains other *Range* numbers set or not\npop()                               Removes and returns last number in *Range*, raises IndexError if list is empty or index is out of range\nremove(number)                      Removes the specified number from self *Range*, raises ValueError if the numbers is not present\nsymmetric_difference(other)         Returns *Range* object with the symmetric differences of self and other *Range*\nsymmetric_difference_update(other)  Inserts the symmetric differences from self *Range* and other *Range*\nupdate(other)                       Returns *Range* of the union of self *Range* and other *Range*\n=================================== ====================================================================================\n\n\n**Examples**\n\n- Attributes demonstration\n- Sorts numbers and removes duplicates\n- Range with custom splitters\n\n`./examples/range.py`_\n\n\n\nNumbers\n-------\n\nparse_range()\n.............\n**parse_range(line, splitter, range_splitter)**\nParses range from line. Removes white spaces considering splitters.\nSort numbers and removes duplicates.\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nline            *str*                       Range of numbers, can be unsorted and with duplicates\nsplitter        *str*                       Separator character between items, by default \",\"\nrange_splitter  *str*                       Separator between min and max numbers in range, by default \"-\"\n=============== =========================== ============================================================================\n\nReturn\n    Range *object*\n\n\ninumbers()\n..........\n**inumbers(items, splitter, range_splitter)**\nSort integer numbers and removes duplicates\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of numbers, can be unsorted and with duplicates\nsplitter        *str*                       Separator character between items, by default \",\"\nrange_splitter  *str*                       Separator between min and max numbers in range, by default \"-\"\n=============== =========================== ============================================================================\n\nReturn\n    *List[int]* of unique sorted numbers\n\n\nsnumbers()\n..........\n**snumbers(items, splitter, range_splitter)**\nSort string numbers and removes duplicates\n\n=============== =========================== ============================================================================\nParameter       Type                        Description\n=============== =========================== ============================================================================\nitems           *str, List[int], List[str]* Range of numbers, can be unsorted and with duplicates\nsplitter        *str*                       Separator character between items, by default \",\"\nrange_splitter  *str*                       Separator between min and max numbers in range, by default \"-\"\n=============== =========================== ============================================================================\n\nReturn\n    *str* of unique sorted numbers\n\n\n**Examples**\n\n- Sorts numbers and removes duplicates\n- Range with custom splitter and range_splitter\n- Converts unsorted range to sorted *List[int]* without duplicates\n- Converts unsorted range to *List[int]* with custom splitters\n- Converts unsorted range to sorted *str* without duplicates\n- Converts unsorted range to *str* with custom splitters\n\n`./examples/numbers.py`_\n\n\nInterfaces\n----------\n\nintfrange()\n...........\n**intfrange(items, fmt)**\nConvert interfaces names to shorted range notation\n\n=========== ============ ===========================================================================\nParameter   Type         Description\n=========== ============ ===========================================================================\nitems       *List[str]*  List of interfaces\nfmt         *str*        Format option: \"long\"  - Long names: [\"interface Ethernet1/1-3\"], \"short\" - Short names: [\"Eth1/1/1-3\"]\n=========== ============ ===========================================================================\n\nReturn\n    *List[str]* Interface ranges\n\n\nlong_to_short()\n...............\n**long_to_short(device_type, key_lower, value_lower)**\nReturns Interfaces map long-to-short, device_type specific\n\n=============== =========================== ============================================================================\nParameter        Type                        Description\n=============== =========================== ============================================================================\ndevice_type     *str*                       Netmiko device type, increase priority of device_type specific keys. \"\", \"cisco_asr\", \"cisco_ios\", \"cisco_nxos\", \"hp_comware\"\nkey_lower       *bool*                      True - keys lower-case, False - keys upper-case\nvalue_lower     *bool*                      True - values lower-case, False - values upper-case\n=============== =========================== ============================================================================\n\nReturn\n    *Dict[str, str]* Interfaces map\n\n\nlong_to_long()\n..............\n**long_to_long(device_type, key_lower, value_lower)**\nReturns Interfaces map long-to-long, device_type specific\n\n=============== =========================== ============================================================================\nParameter        Type                        Description\n=============== =========================== ============================================================================\ndevice_type     *str*                       Netmiko device type, increase priority of device_type specific keys. \"\", \"cisco_asr\", \"cisco_ios\", \"cisco_nxos\", \"hp_comware\"\nkey_lower       *bool*                      True - keys lower-case, False - keys upper-case\nvalue_lower     *bool*                      True - values lower-case, False - values upper-case\n=============== =========================== ============================================================================\n\nReturn\n    *Dict[str, str]* Interfaces map\n\n\nshort_to_long()\n...............\n**short_to_long(device_type, key_lower, value_lower)**\nReturns Interfaces map short-to-long, device_type specific\n\n=============== =========================== ============================================================================\nParameter        Type                        Description\n=============== =========================== ============================================================================\ndevice_type     *str*                       Netmiko device type, increase priority of device_type specific keys. \"\", \"cisco_asr\", \"cisco_ios\", \"cisco_nxos\", \"hp_comware\"\nkey_lower       *bool*                      True - keys lower-case, False - keys upper-case\nvalue_lower     *bool*                      True - values lower-case, False - values upper-case\n=============== =========================== ============================================================================\n\nReturn\n    *Dict[str, str]* Interfaces map\n\n\nshort_to_short()\n................\n**short_to_short(device_type, key_lower, value_lower)**\nReturns Interfaces map short-to-short, device_type specific\n\n=============== =========================== ============================================================================\nParameter        Type                        Description\n=============== =========================== ============================================================================\ndevice_type     *str*                       Netmiko device type, increase priority of device_type specific keys. \"\", \"cisco_asr\", \"cisco_ios\", \"cisco_nxos\", \"hp_comware\"\nkey_lower       *bool*                      True - keys lower-case, False - keys upper-case\nvalue_lower     *bool*                      True - values lower-case, False - values upper-case\n=============== =========================== ============================================================================\n\nReturn\n    *Dict[str, str]* Interfaces map\n\n\nIntf()\n......\n**Intf(line, device_type, splitter)**\nAn object of interface name, that can contain up to 4 indexes.\nSorts the interfaces by indexes (not by alphabetic).\n\n=============== ======= ============================================================================\nParameter       Type    Description\n=============== ======= ============================================================================\nline            *str*   Interface name that can contain up to 4 indexes\ndevice_type     *str*   Netmiko device_type (default \"\")\nsplitter        *str*   Separator of characters between indexes (default \",./:\")\n=============== ======= ============================================================================\n\n\nAttributes\n::::::::::\n\n=============== ============ =======================================================================\nAttributes      Type         Description\n=============== ============ =======================================================================\ndelimiters                   Interface all delimiters\nid0             *str*        Interface name. Line without IDs\nid1             *int*        Interface 1st ID\nid2             *int*        Interface 2nd ID\nid3             *int*        Interface 3rd ID\nid4             *int*        Interface 4th ID\nids                          Interface all IDs\nline            *str*        Interface line\nname            *str*        Interface name with IDs\nsplitter        *str*        Separator of characters between indexes\ndevice_type     *str*        Netmiko device_type\n=============== ============ =======================================================================\n\n\nlast_idx()\n..........\n**last_idx()**\nIndex of last ID in interface line\n\n\nall_names()\n...........\n**all_names()**\nAll variants of names: long, short, upper-case, lover-case. Device type specific\n\n\nname_full()\n...........\n**name_full()**\nInterface long name with IDs and with interface keyword\n\n\nname_long()\n...........\n**name_long()**\nInterface long name with IDs and without interface keyword\n\n\nname_short()\n............\n**name_short(replace)**\nInterface short name with IDs, Device type specific\n\n=========== =========================== ============================================================\nParameter   Type                        Description\n=========== =========================== ============================================================\nreplace     *List[Tuple[str, str]]*     Replace the default short name with the first one\n                                        that matches in the list of the 'replace' argument.\n=========== =========================== ============================================================\n\nReturn\n    *str* Interface short name.\n\n\npart_after()\n............\n**part_after(idx, splitter)**\nInterface part after interested ID\n\n=========== ============ ===========================================================================\nParameter   Type         Description\n=========== ============ ===========================================================================\nidx         *int*        Interface index\nsplitter    *bool*       True - Include splitter from edge, False - Skip splitter from edge\n=========== ============ ===========================================================================\n\nReturn\n    *str* Part of the interface name after specified interface index\n\n\npart_before()\n.............\n**part_before(idx, splitter)**\nInterface part before interested ID\n\n=========== ============ ===========================================================================\nParameter   Type         Description\n=========== ============ ===========================================================================\nidx         *int*        Interface index\nsplitter    *bool*       True - Include splitter from edge, False - Skip splitter from edge\n=========== ============ ===========================================================================\n\nReturn\n    *str* Part of the interface name before specified interface index\n\n\n**Examples**\n\n- Attributes demonstration\n- Interface with custom splitter between indexes. Splitter is ignored when comparing\n- Sorting by indexes\n- Grouping interfaces by 3rd index\n\n`./examples/intfs.py`_\n\n\nSwVersion()\n...........\n**SwVersion(text)**\nParse the given version string and return *SwVersion* object who can\ncompare (>, >=, <, <=) software versions of network devices: Cisco, FortiGate, HP, etc.\n\n\n.. code:: python\n\n    import re\n    from netports import SwVersion\n\n    text = \"Cisco IOS Software, C2960X Software (C2960X-UNIVERSALK9-M), Version 15.2(4)E10, ...\"\n    text = re.search(r\"Version (\\S+),\", text)[1]\n\n    version1 = SwVersion(text)  # 15.2(4)E10\n    version2 = SwVersion(\"15.2(4)E11\")\n\n    assert version1 < version2\n    assert version1 <= version2\n    assert not version1 > version2\n    assert not version1 >= version2\n    print(version1)  # 15.2(4)e10\n    print(version2)  # 15.2(4)e11\n\n\n.. _`./examples/tcp_udp.py` : ./examples/tcp_udp.py\n.. _`./examples/vlan.py` : ./examples/vlan.py\n.. _`./examples/ip.py` : ./examples/ip.py\n.. _`./examples/range.py` : ./examples/range.py\n.. _`./examples/numbers.py` : ./examples/numbers.py\n.. _`./examples/intfs.py` : ./examples/intfs.py\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python tools for managing ranges of VLANs, TCP/UDP ports, IP protocols, Interfaces",
    "version": "0.12.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/vladimirs-git/netports/issues",
        "Download URL": "https://github.com/vladimirs-git/netports/archive/refs/tags/0.12.0.tar.gz",
        "Homepage": "https://github.com/vladimirs-git/netports",
        "Repository": "https://github.com/vladimirs-git/netports"
    },
    "split_keywords": [
        "networking",
        "port",
        "range",
        "tcp",
        "udp",
        "vlan",
        "ip"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "585c6ec2093fea97fadd6777186d94d53e93cbd5775f6e754aaf60136ecf257a",
                "md5": "49eb76987353967c0f14213e36e4a42b",
                "sha256": "c8dc1c6d6d9cdb2685df045fcdbc1973d491b2ccd05a0d14f20363b29bc501d3"
            },
            "downloads": -1,
            "filename": "netports-0.12.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "49eb76987353967c0f14213e36e4a42b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 30093,
            "upload_time": "2023-12-05T13:37:20",
            "upload_time_iso_8601": "2023-12-05T13:37:20.302909Z",
            "url": "https://files.pythonhosted.org/packages/58/5c/6ec2093fea97fadd6777186d94d53e93cbd5775f6e754aaf60136ecf257a/netports-0.12.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2880626a15e276bf81109ebf522e6508dd7219deede936fdc61a7ccbc419bda1",
                "md5": "3d3f51bfaf4c2ffdda2996d3a2573365",
                "sha256": "7a66194c65e35dcd9a99e07ddd488455fc0f3bd27aa5f6bc38a3f08ca78762ac"
            },
            "downloads": -1,
            "filename": "netports-0.12.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3d3f51bfaf4c2ffdda2996d3a2573365",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 26439,
            "upload_time": "2023-12-05T13:37:22",
            "upload_time_iso_8601": "2023-12-05T13:37:22.448085Z",
            "url": "https://files.pythonhosted.org/packages/28/80/626a15e276bf81109ebf522e6508dd7219deede936fdc61a7ccbc419bda1/netports-0.12.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-05 13:37:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vladimirs-git",
    "github_project": "netports",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "netports"
}
        
Elapsed time: 0.16673s