def increment_ip_address(self, addr, val): """ Returns the next valid IP address from a given one, like 10.1.1.254 -> 10.1.1.255 -> 10.1.2.0 -> 10.1.2.1 """ ip2int = lambda ipstr: struct.unpack('!I', socket.inet_aton(ipstr))[0] x = ip2int(addr) int2ip = lambda n: socket.inet_ntoa(struct.pack('!I', n)) return int2ip(x + 1)
def increment_ip_addr(self, ip_address, increment): ip2int = lambda ipstr: struct.unpack('!I', socket.inet_aton(ipstr))[0] x = ip2int(ip_address) int2ip = lambda n: socket.inet_ntoa(struct.pack('!I', n)) return int2ip(x + increment)