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); }
private void netMaskComboBox_SelectedIndexChanged(object sender, System.EventArgs e) { if (ip == null || ip.getIp() == null || fill) { return; } if (ip.getNetworkClassPrefix() == -1) { return; } int select = netMaskComboBox.SelectedIndex; int prefix = select + ip.getNetworkClassPrefix(); if (select != 0 && !ip.isFirstSubNetBit()) { prefix++; } //int prefix = Integer.parseInt((String)main.getJcb_Calc_NetworkMask().getSelectedItem()); ip.setNetworkPrefix(prefix); fillIPCalc(); }