Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

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.

Filename, size & hash SHA256 hash help File type Python version Upload date
jamaddr-0.5-py3-none-any.whl (2.9 kB) Copy SHA256 hash SHA256 Wheel py3 Jun 1, 2018
jamaddr-0.5.tar.gz (2.5 kB) Copy SHA256 hash SHA256 Source None Jun 1, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page