import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
public class IpUtils {
public static void main(String[] args) {
String ip="192.168.100.200";
String mask="31";
System.out.println(parseIpMaskRange(ip, mask).size());;
}
public static List parseIpMaskRange(String ip,String mask){
List list=new ArrayList();
if ("32".equals(mask)) {
list.add(ip);
}else{
String startIp=getBeginIpStr(ip, mask);
String endIp=getEndIpStr(ip, mask);
if (!"31".equals(mask)) {
String subStart=startIp.split("\\.")[0]+"."+startIp.split("\\.")[1]+"."+startIp.split("\\.")[2]+".";
String subEnd=endIp.split("\\.")[0]+"."+endIp.split("\\.")[1]+"."+endIp.split("\\.")[2]+".";
startIp=subStart+(Integer.valueOf(startIp.split("\\.")[3])+1);
endIp=subEnd+(Integer.valueOf(endIp.split("\\.")[3])-1);
}
list=parseIpRange(startIp, endIp);
}
return list;
}
public static List parseIpRange(String ipfrom, String ipto) {
List ips = new ArrayList();
String[] ipfromd = ipfrom.split("\\.");
String[] iptod = ipto.split("\\.");
int[] int_ipf = new int[4];
int[] int_ipt = new int[4];
for (int i = 0; i < 4; i++) {
int_ipf[i] = Integer.parseInt(ipfromd[i]);
int_ipt[i] = Integer.parseInt(iptod[i]);
}
for (int A = int_ipf[0]; A <= int_ipt[0]; A++) {
for (int B = (A == int_ipf[0] ? int_ipf[1] : 0); B <= (A == int_ipt[0] ? int_ipt[1]
: 255); B++) {
for (int C = (B == int_ipf[1] ? int_ipf[2] : 0); C <= (B == int_ipt[1] ? int_ipt[2]
: 255); C++) {
for (int D = (C == int_ipf[2] ? int_ipf[3] : 0); D <= (C == int_ipt[2] ? int_ipt[3]
: 255); D++) {
ips.add(new String(A + "." + B + ".