Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getSubnetInfo(ipaddr, subnet_mask):
- splitMask = map(int, subnet_mask.split('.'))
- splitIpaddr = map(int, ipaddr.split('.'))
- #Find index of magic octet in splitMask(that isn't = to 255)
- magicOctet = 0
- for octet in splitMask:
- if octet == 255:
- magicOctet = magicOctet + 1
- #Value in this index = 255, so search next index
- increment = 256 - splitMask[magicOctet]
- ipaddrOctet = int(ipaddr.split('.')[magicOctet])
- #Keeping track of variables
- print "Original IP: " + str(ipaddr)
- #print "Magic Octet Index: " + str(magicOctet)
- #print "Magic number: " + str(ipaddrOctet)
- #print "Increments: " + str(increment)
- #==============================================#
- networkID = 0
- while ipaddrOctet > networkID:
- networkID = networkID + increment
- networkID = networkID - increment
- broadcast = (networkID + increment) - 1
- print("Network = {}.{}.{}.{}".format(splitIpaddr[0], splitIpaddr[1], splitIpaddr[2], networkID))
- print("First Valid IP = {}.{}.{}.{}".format(splitIpaddr[0], splitIpaddr[1], splitIpaddr[2], networkID + 1))
- print("Broadcast = {}.{}.{}.{}".format(splitIpaddr[0], splitIpaddr[1], splitIpaddr[2], broadcast))
- getSubnetInfo("192.168.123.10", "255.255.255.224")
Advertisement
Add Comment
Please, Sign In to add comment