Skip to main content

I have written my own python ip/subnet tool. It's for python2/3. Use theese methods to conver ip mask formats and to check if ip/subnet belong to other subnet. I made it partly for fun and to learn, so perhaps these are not the best, but they get the job done. Checking if ip belongs to subnet is actually about 20-30% faster, than with tools from netaddr module.

Methods provided:

  • is_in_subnet : check if ip belongs to subnet
  • is_in_range : check if ip belongs to ip range
  • verify : check if ip or ip/netmask are valid
  • get_subnet_ip : get subnet ip for some ip/mask
  • mask255_to_dec : convert ip mask format
  • dec_to_mask255 : convert ip mask format
  • is_mask : check if ip mask is real

Instalation:

pip install iptoolsjj

Import:

import iptoolsjj

Examples:

Check if 192.168.10.10 is inside 192.168.10.0/22:

print(iptoolsjj.is_in_subnet('192.168.10.10', '192.168.10.0/22'))

Check if 192.168.51.1 is between 192.168.50.100 and 192.168.60.50:

print(iptoolsjj.is_in_range('192.168.50.100','192.168.60.50','192.168.51.1'))

Verify if ip or ip with mask is in good format:

print(iptoolsjj.verify('192.168.1.22'))
print(iptoolsjj.verify('192.168.1.22/25','ip/mask'))
print(iptoolsjj.verify('192.168.1.22/255.255.255.128','ip/mask255'))

Get subnet ip for given ip address:

print(iptoolsjj.get_subnet_ip('191.123.1.36/27'))

Convert mask '255.255.255.240' to '28':

print(iptoolsjj.mask255_to_dec('255.255.255.240'))

Convert mask '28' to '['255', '255', '255', '240']' (normally it's list format):

print(iptoolsjj.dec_to_mask255(28))

or

print('.'.join(iptoolsjj.dec_to_mask255(28)))

Check if mask is real mask in format xxx.xxx.xxx.xxx:

print(is_mask("255.255.255.0"))

Metadata

Release files for iptoolsjj 1.4.1

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

Source distribution (sdist)

Source distribution for iptoolsjj 1.4.1
File Size Uploaded
iptoolsjj-1.4.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iptoolsjj 1.4.1
File Interpreter ABI Platform
iptoolsjj-1.4.1-py2-none-any.whl Python 2 none any Details

Total release size: 9.7 kB

Release files / iptoolsjj-1.4.1.tar.gz

Download URL iptoolsjj-1.4.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
26c53000668f075a01aafc02cf2a6e4979a82276e623b7997f4a5a92c486d32c
BLAKE2b-256 checksum
How to use checksums
742c12380704af9097392460ec1c89a78715dbd13f8821bc3cb5289332a492bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.12.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.5.3

Release files / iptoolsjj-1.4.1-py2-none-any.whl

Download URL iptoolsjj-1.4.1-py2-none-any.whl
Size 5.4 kB
Tags Python 2
SHA-256 checksum
How to use checksums
30b4970dfed69598b22fee6dff94b553f2422f2ec503fb2902b6d9311680f7a8
BLAKE2b-256 checksum
How to use checksums
db36c40fad57ec07873129db1ecd1f2e1485802120ffb6099d69be1e6e3e95cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.12.4 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.5.3

Release history Release notifications | RSS feed

1.4.2

2 release files

This release

1.4.1 This release

2 release files

1.3.0

1 release file

1.2.6

2 release files

1.2.5

1 release file

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

1 release file

1.2

1 release file

1.1

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

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