Am looking for a Java code snippet, which gives the next address from the given IP.
Here's a snippet for you:
public static String getNextIPV4Address(String ip) {
String[] nums = ip.split("\\.");
int i = (Integer.parseInt(nums[0]) << 24 | Integer.parseInt(nums[2]) << 8
| Integer.parseInt(nums[1]) << 16 | Integer.parseInt(nums[3])) + 1;
// If you wish to skip over .255 addresses.
if ((byte) i == -1) i++;
return String.format("%d.%d.%d.%d", i >>> 24 & 0xFF, i >> 16 & 0xFF,
i >> 8 & 0xFF, i >> 0 & 0xFF);
}
Examples input / output (ideone.com demonstration):
10.1.1.0 -> 10.1.1.1
10.255.255.255 -> 11.0.0.0
10.0.255.254 -> 10.1.0.0