1
Scripting Languages / Re: [Python] Subnet Calculator
« on: August 14, 2015, 01:12:10 AM »Code: (python) [Select]#!/usr/bin/env python2
def calcSubnet(cidr):
"""
Calculates the Subnet
based on the CIDR
"""
subn = 4294967295 << (32-cidr) # 4294967295 = all bits set to 1
subn = subn % 4294967296 # round it back to be 4 bytes
subn = calcIPNotation(subn)
return subn
As I work through this more, I think I understand how you found '4294967295 '. Although 2^32 = 4294967296, is no the same as this; ( (((2^(8*3))*255)+(((2^(8*2))*255)+(((2^(8*1))*255)+(((2^(8*0))*255))))) ) = 4294967295, which is "255.255.255.255" technically the same value. Still researching as to why that is, but at least that explains what's going on.