PYTHON PROGRAM FOR FLSM USING CLASS C IP ADDRESS ONLY
ip,cidr=input("Enter
the the Network ID with CIDR value for which you need FLSM (ONLY FOR CLASS C):
").split('/')
ip1,ip2,ip3,ip4=ip.split('.')
req_host=int(input("Enter
the no of Required Host: "))
for h
in range(0,15):
if
2**h
>= req_host:
sm=int(cidr)+8-h
nid=8-h
for
i in
range(2**nid):
valid_host=(2**h)*i
print(f"{ip1}.{ip2}.{ip3}.{int(ip4)+valid_host}/{sm}")
break
OUTPUT
RESULT
Note: I n the Above Program I have created two variables on the first line named “IP and CIDR” These two variables are taking the input of Network ID and CIDR value of any class “C” subnet as a string and then splitting it with ‘/’ than on the next line I have created 4 variables which are dividing the IPv4 32 Bit into 4 octets and storing it into sperate variables that am asking the user for the required no of host required for each FLSM Network. So once I get all this information and run a for loop till 15 (as we all know that the maximum we can till “2^16” i.e; 65,536 hosts) inside the loop there is a if……..condition which is basically checking whether this expression “2^h >= req_host” (here ‘h’ is nothing but the host which should be greater than or equal to the required host) when the condition is true that means I got the required bit what I have done here is I have created a variable called “SM” in which I have subtracted the total network bit (8) from the required (2) which I have added to the variable called CIDR that was nothing but the default subnet of class C which was in my case /24 CIDR after that I have created a variable called “nid” where I have “8-h” and then again there is a for loop which will run till 2^nid and inside the valid_host variable it will store “2^h*i” (It is the actually the valid host which ne
Comments
Post a Comment