Skip to main content

License Python application

Ip-Model

A Data Structure for efficiently storing, removing and checking all Ipv4 addresses in O(1) time.

Pre-requisite

  • pytest

Usage

Single Ip's

Ipv4

from ip_model.Ipv4 import Ipv4

blacklist = Ipv4()

To add an IP:

# arg: String
# returns: True
blacklist.add("192.0.0.18")

To remove an IP:

# arg: String
# returns: removed IP
blacklist.remove("192.0.0.18")

To check if an IP is present/not:

# arg: String
# returns: bool
blacklist.is_present("192.0.0.18")

Ipv6

from ip_model.Ipv4 import Ipv6

blacklist = Ipv6()

To add an IP:

# arg: String
# returns: True
blacklist.add("192::18")

To remove an IP:

# arg: String
# returns: removed IP
blacklist.remove("192:ffff:e034::23")

To check if an IP is present/not:

# arg: String
# returns: bool
blacklist.is_present("::5:4fed")

CIDR

Ipv4:

To Add

# arg: String
# returns: True
blacklist.add_cidr("192.92.53.0/24")
# arg: String
# returns: True
blacklist.add_cidr("192.92.53.0/255.255.255.252")

To remove:

# arg: String
# returns: removed CIDR
blacklist.remove_cidr("192.92.53.0/24")

Ipv6:

To Add

# arg: String
# returns: True
blacklist.add_cidr("8653:53fe::/122/24")

To remove:

# arg: String
# returns: removed CIDR
blacklist.remove_cidr("8653:53fe::/122")

Note:

The tradeoff is, the call for how to handle with overlapping CIDR's must be taken by the service using the DS. The DataStructure only performs the requested operation with the given data

Ip Class (From v3.0.0)

Handles both Ipv4 and Ipv6

from ip_model.Ip import Ip

blacklist = Ip()

To add an IP:

# arg: String
# returns: True
blacklist.add("192.0.0.18")
blacklist.add("192::18")

To remove an IP:

# arg: String
# returns: removed IP
blacklist.remove("192.0.0.18")
blacklist.remove("1924::18")

Exception Handling

  • Throws TypeError: passing Invalid Datatype, incorrect number of arguments
  • Throws InvalidIpException: When an invalid Ip is passed
from ip_model.Exceptions import InvalidIpException

try:
    blacklist.add("192.455.554.343")
except InvalidIpException:
    print("Incorrect Ipv4 Address")

# For CIDR
try:
    blacklist.add("192.12.65.0/16")
except InvalidIpException:
    print("Incorrect CIDR")

ChangeLog

  • v3.0.0

Introducing IP class Return types for add, remove, add_cidr, remove_cidr have been changed

  • v2.0.1

Fix a bug in Ipv6

  • v2.0.0

Adding Support for Ipv6 addresses & CIDR for the same

  • v1.1.0

Adding Support for Ipv4 CIDR ranges

  • v1.0.0

Introducing Ip model with support for single Ipv4 address

Metadata

Release files for ip-model 3.0.0

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

Built distribution (wheel)

Table of built distributions (wheels) for ip-model 3.0.0
File Interpreter ABI Platform
ip_model-3.0.0-py3-none-any.whl Python 3 none any Details

Release files / ip_model-3.0.0-py3-none-any.whl

Download URL ip_model-3.0.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1030effca64476d3566a212ce87366ae0a1e6a4747a2d5af160ca6c1a94d4159
BLAKE2b-256 checksum
How to use checksums
a0fcf71b857a2ec6ceeb50e307033700947f37866e978c1f91f9af2d0a766e61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

3.0.0 This release

1 release file

2.0.1

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.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