We are looking for a piece of Java code that gives the following address from this IP.
Here is 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); }
I / O examples ( ideone.com demo ):
10.1.1.0 -> 10.1.1.1 10.255.255.255 -> 11.0.0.0 10.0.255.254 -> 10.1.0.0
source share