public IPTool getNextSubNet(long numberOfHosts) { IPTool ip = IPTool.getNextIP(this.getBroadCast()); ip.setIp(this.long2String(ip.ip2Long() + (long)1)); ip.setFirstSubNetBit(this.isFirstSubNetBit()); int lastPrefix = ip.getNetworkClassPrefix(); int prefix = 30; do { if (prefix < ip.getNetworkClassPrefix()) { return(null); // no subnet found } ip.setNetworkPrefix(prefix); prefix--; // ignore subnetbit? if (!ip.isFirstSubNetBit() && prefix == lastPrefix + 1) { prefix--; } }while (ip.getMaxNetworkHosts() < numberOfHosts); return(ip); }