How to use the netmask.Netmask function in netmask

To help you get started, we’ve selected a few netmask examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github silklabs / silk / bsp-gonk / vendor / silk / silk-wifi / index.js View on Github external
const mask = util.getstrprop(`${ifacePrefix}.mask`);
  const gateway = util.getstrprop(`${ifacePrefix}.gateway`);
  const domain = util.getstrprop(`${ifacePrefix}.domain`, 'localdomain');

  log.info(`DHCP configuration:\n` +
           `interface: ${iface}\n` +
           `ipaddress: ${ipaddress}/${mask}\n` +
           `dns: ${String(dns)}\n` +
           `gateway: ${gateway}\n` +
           `domain: ${domain}`);

  if (!ipaddress) {
    throw new Error(`dhcpd has not given us an address yet`);
  }

  const block = new Netmask(ipaddress, mask);
  const baseMask = block.base + '/' + block.bitmask;

  log.info(`base: ${baseMask}`);

  // Add basic routing table and DNS
  await execThrowOnNonZeroCode(
    'ndc',
    ['network', 'destroy', '100'],
    abortPromise,
  );
  await execThrowOnNonZeroCode(
    'ndc',
    ['network', 'create', '100'],
    abortPromise,
  );
  await execThrowOnNonZeroCode(
github brave-intl / bat-ledger / bat-utils / lib / hapi-auth-whitelist.js View on Github external
whitelist.forEach((entry) => {
    if ((entry.indexOf('/') !== -1) || (entry.split('.').length !== 4)) return authorizedBlocks.push(new Netmask(entry))

    authorizedAddrs.push(entry)
  })
}
github gardener / dashboard / frontend / src / utils / createShoot.js View on Github external
export function splitCIDR (cidrToSplitStr, numberOfNetworks) {
  const cidrToSplit = new Netmask(cidrToSplitStr)
  const numberOfSplits = Math.ceil(Math.log(numberOfNetworks) / Math.log(2))
  const newBitmask = cidrToSplit.bitmask + numberOfSplits
  if (newBitmask > 32) {
    throw new Error(`Could not split CIDR into ${numberOfNetworks} networks: Not enough bits available`)
  }
  const newCidrBlock = new Netmask(`${cidrToSplit.base}/${newBitmask}`)
  const cidrArray = []
  for (var i = 0; i < numberOfNetworks; i++) {
    cidrArray.push(newCidrBlock.next(i).toString())
  }
  return cidrArray
}
github yuvadm / cidr.xyz / src / index.js View on Github external
render() {
    var details = new Netmask(this.getPretty());

    return (
      <div>
        <div>
          {[...Array(4)].map((x, octet) =&gt; (
            <span>
              <input value="{this.state.octets[octet]}" data-octet="{octet}" type="text">
              <span>{octet == '3' ? '/' : '.'}</span>
            </span></div></div>
github pmcclure / storm-control / src / components / Subnetting / Subnetting.js View on Github external
getHosts() {
		if ((this.getValidationStateSubnet() === 'success') && (this.getValidationStateMask() === 'success')) {
			const hosts = new Netmask(`${this.state.subnet}/${this.state.mask}`);
			return hosts.size;
		}
	}
github mellow-io / mellow / src / main.js View on Github external
function findTunInterface() {
  ifaces = os.networkInterfaces()
  for (k in ifaces) {
    for (let addrObj of ifaces[k]) {
      cidr = addrObj['cidr']
      if (addrObj['family'] == 'IPv4' && !addrObj['internal'] && cidr !== undefined) {
        block = new Netmask(cidr)
        if (block.contains(tunGw)) {
          return {address: addrObj['address'], interface: k}
        }
      }
    }
  }

  return null
}
github pmcclure / storm-control / src / components / Subnetting / Subnetting.js View on Github external
getNetworkAddress() {
		if ((this.getValidationStateSubnet() === 'success') && (this.getValidationStateMask() === 'success')) {
			const networkAddress = new Netmask(`${this.state.subnet}/${this.state.mask}`);
			return networkAddress.base;
		}
	}
github luminati-io / luminati-proxy / lib / server.js View on Github external
const get_random_ip = ()=>{
            if (!last_ip)
                last_ip = new Netmask('1.1.1.1');
            else
                last_ip = last_ip.next();
            return last_ip.base;
        };
        const get_ip = (session={})=>{
github pmcclure / storm-control / src / components / Subnetting / Subnetting.js View on Github external
getNetmask() {
		if ((this.getValidationStateSubnet() === 'success') && (this.getValidationStateMask() === 'success')) {
			const netMask = new Netmask(`${this.state.subnet}/${this.state.mask}`);
			return netMask.mask;
		}
	}

netmask

Parse and lookup IP network blocks

MIT
Latest version published 3 years ago

Package Health Score

72 / 100
Full package analysis

Popular netmask functions