Hello,
The below code is used to increment the ip address by a given step for a particular class.
The ip address should not have 0 or 255 in it.
Thank you in advance.
The below code is used to increment the ip address by a given step for a particular class.
The ip address should not have 0 or 255 in it.
#IP increment function ip = raw_input("Enter IP address: ") step = int(input("Enter the step: ")) class_sel = raw_input("Enter the class: ") def nextIP(ip, step, class_sel): class_sel.lower() octetList = ip.split('.') octetList[3] = int(octetList[3]) octetList[2] = int(octetList[2]) octetList[1] = int(octetList[1]) octetList[0] = int(octetList[0]) iplist = [0,0,0,0] j = ord(class_sel) - ord('a') iplist[j] = octetList[j] + step while j >= 0: if iplist[j] > 254: octetList[j] = iplist[j] % 255 if octetList[j] == 0: octetList[j] = 1 j = j - 1 if j >= 0: octetList[j] = octetList[j] + (iplist[j+1] / 255) else: j = j - 1 print '{}.{}.{}.{}'.format(octetList[0],octetList[1],octetList[2],octetList[3]) return '{}.{}.{}.{}'.format(octetList[0],octetList[1],octetList[2],octetList[3]) nextIP(ip, step, class_sel)The code is not working for boundary conditions. Like
ip: 254.254.254.254 step: 1 class: d o/p: 254.254.254.1 expected o/p: 1.1.1.1Could anyone please help how to make the code work for boundary conditions also.
Thank you in advance.