Code Monkey home page Code Monkey logo

cidr-brewer's Introduction

CIDR Brewer

Copyright 2016-2024 Caleb Evans
Released under the MIT license

tests Coverage Status

CIDR Brewer is a command-line utility which displays information for classless IP addresses (such as subnet mask and network ID) so you don't need to perform the calculations yourself.

Installing

You can install CIDR Brewer via pip (ideally globally):

pip install cidr-brewer

Usage

To use, run cidr-brewer from the command line with one or two IP addresses.

One IP address

If you pass a single IP address using slash notation, CIDR Brewer will compute the subnet mask, network ID, broadcast ID, and the range of valid/available IP addresses.

$ cidr-brewer 192.168.19.100/25
Given IP address:
   192.168.19.100/25  11000000.10101000.00010011.01100100
Subnet mask:
   255.255.255.128    11111111.11111111.11111111.10000000
Network ID:
   192.168.19.0/25    11000000.10101000.00010011.00000000
Broadcast ID:
   192.168.19.127     11000000.10101000.00010011.01111111
First Available Address:
   192.168.19.1       11000000.10101000.00010011.00000001
Last Available Address:
   192.168.19.126     11000000.10101000.00010011.01111110
Subnet Size: 2^7 - 2 = 126

Additionally, if you supply a list of block sizes, CIDR Brewer will compute the same information for each sub-block.

$ cidr-brewer 42.114.152.128/25 --block-sizes 16 64 16 32
Given IP address:
   42.114.152.128/25  00101010.01110010.10011000.10000000
Block 1:
   Block Size: 2^6 = 64
   Network ID:
      42.114.152.128/26  00101010.01110010.10011000.10000000
   Broadcast ID:
      42.114.152.191     00101010.01110010.10011000.10111111
   First Available Address:
      42.114.152.129     00101010.01110010.10011000.10000001
   Last Available Address:
      42.114.152.190     00101010.01110010.10011000.10111110
   Subnet Size: 2^6 - 2 = 62
Block 2:
   Block Size: 2^5 = 32
   Network ID:
      42.114.152.192/27  00101010.01110010.10011000.11000000
   Broadcast ID:
      42.114.152.223     00101010.01110010.10011000.11011111
   First Available Address:
      42.114.152.193     00101010.01110010.10011000.11000001
   Last Available Address:
      42.114.152.222     00101010.01110010.10011000.11011110
   Subnet Size: 2^5 - 2 = 30
Block 3:
   Block Size: 2^4 = 16
   Network ID:
      42.114.152.224/28  00101010.01110010.10011000.11100000
   Broadcast ID:
      42.114.152.239     00101010.01110010.10011000.11101111
   First Available Address:
      42.114.152.225     00101010.01110010.10011000.11100001
   Last Available Address:
      42.114.152.238     00101010.01110010.10011000.11101110
   Subnet Size: 2^4 - 2 = 14
Block 4:
   Block Size: 2^4 = 16
   Network ID:
      42.114.152.240/28  00101010.01110010.10011000.11110000
   Broadcast ID:
      42.114.152.255     00101010.01110010.10011000.11111111
   First Available Address:
      42.114.152.241     00101010.01110010.10011000.11110001
   Last Available Address:
      42.114.152.254     00101010.01110010.10011000.11111110
   Subnet Size: 2^4 - 2 = 14

Two IP addresses

If you pass two IP addresses (without slash notation), CIDR Brewer will also compute the largest subnet mask needed for communication between the two addresses.

$ cidr-brewer 172.16.11.74 172.16.11.78
Given IP addresses:
   172.16.11.74       10101100.00010000.00001011.01001010
   172.16.11.78       10101100.00010000.00001011.01001110
Largest subnet mask allowing communication:
   29 bits
   255.255.255.248    11111111.11111111.11111111.11111000
Network ID:
   172.16.11.72/29    10101100.00010000.00001011.01001000
Broadcast ID:
   172.16.11.79       10101100.00010000.00001011.01001111
First Available Address:
   172.16.11.73       10101100.00010000.00001011.01001001
Last Available Address:
   172.16.11.78       10101100.00010000.00001011.01001110
Subnet Size: 2^3 - 2 = 6

If you pass two IP addresses (with slash notation), CIDR Brewer will also indicate if the IP addresses can already communicate on their respective subnets.

$ cidr-brewer 125.47.32.170/25 125.47.32.53/25
Given IP addresses:
   125.47.32.170/25   01111101.00101111.00100000.10101010
   125.47.32.53/25    01111101.00101111.00100000.00110101
Can these IP addresses communicate?
   No
Largest subnet mask allowing communication:
   24 bits
   255.255.255.0      11111111.11111111.11111111.00000000
Network ID:
   125.47.32.0/24     01111101.00101111.00100000.00000000
Broadcast ID:
   125.47.32.255      01111101.00101111.00100000.11111111
First Available Address:
   125.47.32.1        01111101.00101111.00100000.00000001
Last Available Address:
   125.47.32.254      01111101.00101111.00100000.11111110
Subnet Size: 2^8 - 2 = 254

Examples

The /examples directory contains example IP addresses for you to test against the utility.

cidr-brewer's People

Contributors

caleb531 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

z00dev llchen223

cidr-brewer's Issues

Incompatible with Py2.7

The project README doesn't specify a python version so when installing against Py2.7 it doesn't work properly. Specifically there's no log2 function in earlier Python versions, but it's easily fixed by changing it to log(x, 2) rather than log2(x)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.