Skip to main content

netprot

A system-independent network protocol manipulation and evaluation library. netprod wants to be a library capable of standardizing and evaluating a list of strings representing Network Protocols. The idea is to provide a tool similar to netaddr that can help to enhance and simplify code logic wherever is required.

Installation

pip3 install netprod

Package available here

HOW TO

First thing, we need to initialize an instance of Netprod class, passing as arguments a list of strings - where each string should represent a network protocol and corresponding port. A separator argument is also possible to pass as kwarg and will be used to standardize our strings. By default, separator is equal to /

>>> from netprot.netprot import Netprot 
>>> my_list = ['tcp-443-https', 'UDP/53', 'tcp/1024-1026', 'TCPP-80', 'tcp/443']
>>> my_protocols = Netprot(my_list, exceptions=['ICMP', 'any'], separator='/')

Once the instance of the class is created, we can call standardize method which will return a tuple containing pontential unlegal protocols and ports, duplicates - if any, and a standardize list of protocols and port.

>>> my_protocols.standardize()
(['TCPP/80'], ['TCP/443'], ['ANY', 'ICMP', 'TCP/1024', 'TCP/1025', 'TCP/1026', 'TCP/443', 'UDP/53'])

As we can see, we have:

  • Strings using the same separator.
  • Trailing words such as https is removed as not needed
  • Protocols defined as tcp/1024-1026 are unpacked for each port in range defined
  • Illegal protocols such as TCPP/80 are removed
  • Duplicates are also removed
  • All strings are upper cases
  • List is sorted
  • ICMP and ANY are recognized as legal - because defined under exceptions argument - and passed through

Netprod not only standardizes data, but also evaluates them. Let's have a look to the other methods

:warning: List of protocols must be standardized first.

Let's check if the ports are part of well known range of ports (0 to 1024)

>>> my_protocols.is_well_known()
(False, [False, False, True, False, False, True, True])

As we can see, some ports are failing to be lower than 1024, hence we return False plus a list of bools for each ports.

What about if we want to find those are TCP...

>>> my_protocols.is_tcp()
(False, [False, False, True, True, True, True, False])

... or UDP?

>>> my_protocols.is_udp()
(False, [False, False, False, False, False, False, True])

Great! What if we want figure out if our port and protocols are safe or not? Let's define a list of safe - or unsafe - ports and protocols and passed them to is_safe or is_unsafe method.

>>> my_safe_applications = ['TCP/443', 'UDP/53']
>>> my_protocols.is_safe(my_safe_applications)
[False, False, False, False, False, True, True]
>>> my_unsafe_applications = ['ICMP', 'ANY']
>>> my_protocols.is_unsafe(my_unsafe_applications)
[True, True, False, False, False, False, False]

And that's all, folks!

Metadata

Release files for netprot 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for netprot 0.1.2
File Size Uploaded
netprot-0.1.2.tar.gz 17.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for netprot 0.1.2
File Interpreter ABI Platform
netprot-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 46.5 kB

Release files / netprot-0.1.2.tar.gz

Download URL netprot-0.1.2.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d7d3e2cd39bfd19eb8d8263cf231614b043d8de084db97ef210eede40bc002ec
BLAKE2b-256 checksum
How to use checksums
e132d4ff5ba348edb5baad2ed2d97cebe7029363c0a50a7286c60b6883bdfc99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.7

Release files / netprot-0.1.2-py3-none-any.whl

Download URL netprot-0.1.2-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2062d8a4252323c2e37d5b0a8b299cfea32a560cf91074859d3e65c7eff55134
BLAKE2b-256 checksum
How to use checksums
7344985397dc340d656af35cc6e5ea2d59808bc28085fe22a4d370ea806d6ea4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.7

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page