Eli Fulkerson .com HomeProjectsPython-subnet-allocator
 

Python Subnet Allocator

Description:

This is a small recursive function that draws an IP space layout based on a few parameters. It breaks down a large IP space (for intance a /16) into smaller networks as specified (down to /30). In order to collapse out unnecessary data, you can optionally specify a network size you are interested in (for instance, /24) and only display the networks at that scale. Text descriptions can be attached to any given subnet/subnet mask combination... described networks will always be shown.

Platform:

  • no platform specific code, should work anywhere that has Python
  • Language:

  • Python
  • Usage:

    #The network number to start with...
    start = ip_to_base10("172.20.128.0")
    
    #An 'interesting' network size will always be shown, regardless if its used.  Set to 0 if you don't want it.
    interesting = 22
    
    #The network size to start drawing from ( 0 to 30)
    draw_from = 17
    
    #the network size to stop drawing at (0 to 30, should be smaller (in size... /0 is largest, /30 smallest) than draw_from)
    draw_to = 18
    
    #OK, draw it
    drawsubnet(draw_from, draw_to, interesting, start)
    

    Example Output:

    /17                    172.20.128.0 - 255.255.128.0 - 32766 hosts - (2 /18's under)
     /18                   172.20.128.0 - 255.255.192.0 - 16382 hosts
         /22               172.20.128.0 - 255.255.252.0 - 1022 hosts - New York /22
         /22               172.20.132.0 - 255.255.252.0 - 1022 hosts - Los Angeles /22
         /22               172.20.136.0 - 255.255.252.0 - 1022 hosts - Chicago /22
         /22               172.20.140.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.144.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.148.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.152.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.156.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.160.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.164.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.168.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.172.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.176.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.180.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.184.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.188.0 - 255.255.252.0 - 1022 hosts
     /18                   172.20.192.0 - 255.255.192.0 - 16382 hosts
         /22               172.20.192.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.196.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.200.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.204.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.208.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.212.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.216.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.220.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.224.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.228.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.232.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.236.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.240.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.244.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.248.0 - 255.255.252.0 - 1022 hosts
         /22               172.20.252.0 - 255.255.252.0 - 1022 hosts - Administrivia
           /24             172.20.255.0 - 255.255.255.0 - 254 hosts - Management Networks
                /29        172.20.255.0 - 255.255.255.248 - 6 hosts - Management network A
                /29        172.20.255.8 - 255.255.255.248 - 6 hosts - Management network B
    

    Source code