public static String getEndIpForIpv4(String startIp, int count) throws Exception {
if (count <= 0) {
return startIp;
}
String[] split = startIp.split("\.");
int v1 = Integer.parseInt(split[0]);
int v2 = Integer.parseInt(split[1]);
int v3 = Integer.parseInt(split[2]);
int v4 = Integer.parseInt(split[3]);
int size = v4 + count - 1;
if (size < 256) {
v4 = size;
return v1 + "." + v2 + "." + v3 + "." + v4;
}
int m4 = size % 256;
int y4 = size / 256;
v4 = m4;
//进位后的数量
size = y4 + v3;
//如果没超过255输出 超过255继续进位
if (size < 256) {
v3 = size;
return v1 + "." + v2 + "." + v3 + "." + v4;
}
int m3 = size % 256;
int y3 = size / 256;
v3 = m3;
size = y3 + v2;
if (size < 256) {
v2 = size;
return v1 + "." + v2 + "." + v3 + "." + v4;
}
int m2 = size % 256;
int y2 = size / 256;
v2 = m2;
size = y2 + v1;
if (size < 256) {
v1 = size;
return v1 + "." + v2 + "." + v3 + "." + v4;
} else {
//ip不是正确ip
throw new Exception();
}
}