Skip to main content

IP Subnet package

Project description

Jamaddr Python Package

This package Created by Jamison Emilio and packaged by Todd Albiston

Installation Python3.6 and above

pip3 install jamaddr 

for python 2.7.12 and above see jamaddr27 https://github.com/talbiston/jamaddr27

Description:

Python Package adds functions to convert IP address or subnet masks to bits and bits back to IP address.

from jamaddr import JamAddr
ipbits = JamAddr.ip_to_bits("192.168.0.23")
ipbits

returns = '11000000101010000000000000010111'
from jamaddr import JamAddr
bitsip = JamAddr.bits_to_ip("11000000101010000000000000010111")
bitsip

returns = '192.168.0.23'

Of course you could also enter a subnet mask to convert to bits then do the same with its corresponding IP, then work out what the network ID or Broadcast IPs would be or use your imagination on what other use cases could be.

from jamaddr import JamAddr

def network_id(ip_cidr):

    ip, cidr = ip_cidr.split('/')
    ip_bits = JamAddr.ip_to_bits(ip)[:int(cidr)] + '0' * (32 - int(cidr))
    return '{}/{}'.format(JamAddr.bits_to_ip(ip_bits), cidr)

networkID = network_id("192.168.0.23/28")
print(networkID)

returns = 192.168.0.16/28

This example above is already included as a function in this package so you could just do the following, but you get the point.

from jamaddr import JamAddr

networkID = JamAddr.network_id("192.168.0.23/28")
print(networkID)

returns = 192.168.0.16/28

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

jamaddr-0.5.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jamaddr-0.5-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file jamaddr-0.5.tar.gz.

File metadata

  • Download URL: jamaddr-0.5.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for jamaddr-0.5.tar.gz
Algorithm Hash digest
SHA256 6e8aef1e1f127bb94e3177c7f2ad3857937dacc6c11555c707e03579f328db03
MD5 7dd88dab2c44002c00102f85e04177e1
BLAKE2b-256 20409d07706859af20623b40b3c5acfa2df2ece1cf43b3b48949d3e333d324c2

See more details on using hashes here.

File details

Details for the file jamaddr-0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for jamaddr-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dc1729e605aa3fa4478c3a641c19bff75eca20fb884da48ca2baaf1dd8cdb4ae
MD5 a8567fe65885e0523c21d3ef1e2fc821
BLAKE2b-256 c70b772c018c351a31ff188ec4def63a5f2dae09d5fab1dd0415ce5778cd1e7e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page