def init(args=None): try: network = args['NETWORK'] mask = args['MASK'] except: return "10.2.1.241" if mask<=8: ip=calc_num_ip(mask) ultima_ip=network.split(".") ultima_ip[1]=str(ip) ultima_ip[2]="255" ultima_ip[3]="241" ultima_ip = '.'.join(map(str, ultima_ip)) return ultima_ip else: if mask<=16: mask=mask-8 ip=calc_num_ip(mask) ultima_ip=network.split(".") ultima_ip[2]=str(ip) ultima_ip[3]="241" ultima_ip = '.'.join(map(str, ultima_ip)) return ultima_ip else: if mask<=24: mask=mask-16 ip=calc_num_ip(mask) ip=last_ip(ip) ultima_ip=network.split(".") ultima_ip[3]=str(ip) ultima_ip = '.'.join(map(str, ultima_ip)) return ultima_ip #if #else #else #if #def init def last_ip(availables): if availables<=2: return 0 if availables<=10: return availables-2 if availables<=30: return availables-10; return availables-15 #def last_ip def calc_num_ip(bits): ultima_ip=1 for num in range(0,bits): ultima_ip=ultima_ip*2 if ultima_ip==256: ultima_ip=255 return ultima_ip #def calc_last_ip #init({'NETWORK':"10.2.1.0",'MASK':24})