How to use the ip.subnet function in ip

To help you get started, we’ve selected a few ip 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 senecajs / seneca-mesh / mesh.js View on Github external
multicast: function(seneca, opts, bases, next) {
        var add = []
        var mc_opts = opts.discover.multicast

        // Determine broadcast address using subnetmask
        if (_.isString(mc_opts.address) && '/' === mc_opts.address[0]) {
          var netprefix = parseInt(mc_opts.address.substring(1), 10)
          mc_opts.address = Ip.subnet(
            opts.host,
            Ip.fromPrefixLen(netprefix)
          ).broadcastAddress
        }

        var d = Discover({
          broadcast: mc_opts.address,
          advertisement: {
            seneca_mesh: true,
            isbase: opts.isbase,
            host: opts.host || DEFAULT_HOST,
            port: opts.port || DEFAULT_PORT
          }
        })

        var findCount = 0
github DeadPackets / HackPi / server / functions / fn.js View on Github external
ifconfig.status(iface, (err, status) => {
		if (err)
			cb('fail', err)
		var check = TRACK_IFACES.indexOf(iface)
		if (IFACES_STATE[check].state.busy == false) {
			var subnet = ip.subnet(status.ipv4_address, status.ipv4_subnet_mask).subnetMaskLength
			localrange = status.ipv4_address + '/' + subnet

			IFACES_STATE[check].state.busy = true
			IFACES_STATE[check].state.process = "Local nmap scan of range " + localrange

			var nmapscan = new nmap.nodenmap.NmapScan(localrange, '-sn', '-T4', '--max-retries 1', '-e ' + iface);
			console.log("Created new scan", localrange)

			nmapscan.on('error', (error) => {
				cb('fail', error)
			});
			//Add to interface status array that this iface is now busy with a ping sweep.
			nmapscan.on('complete', (data) => {
				IFACES_STATE[check].state.busy = false
				IFACES_STATE[check].state.process = 'none'
				cb('success', data, nmapscan.scanTime)
github timonreinhard / wemo-client / index.js View on Github external
Wemo.prototype.getLocalInterfaceAddress = function(targetNetwork) {
  var interfaces = os.networkInterfaces();
  if (this._listenInterface) {
    if (interfaces[this._listenInterface]) {
      interfaces = [interfaces[this._listenInterface]];
    } else {
      throw new Error('Unable to find interface ' + this._listenInterface);
    }
  }
  var addresses = [];
  for (var k in interfaces) {
    for (var k2 in interfaces[k]) {
      var address = interfaces[k][k2];
      if (address.family === 'IPv4' && !address.internal) {
        if (targetNetwork && ip.subnet(address.address, address.netmask).contains(targetNetwork)) {
          addresses.unshift(address.address);
        } else {
          addresses.push(address.address);
        }
      }
    }
  }
  return addresses.shift();
};
github DylanPiercey / local-devices / src / index.js View on Github external
function getServers () {
  var interfaces = os.networkInterfaces()
  var result = []

  for (var key in interfaces) {
    var addresses = interfaces[key]
    for (var i = addresses.length; i--;) {
      var address = addresses[i]
      if (address.family === 'IPv4' && !address.internal) {
        var subnet = ip.subnet(address.address, address.netmask)
        var current = ip.toLong(subnet.firstAddress)
        var last = ip.toLong(subnet.lastAddress) - 1
        while (current++ < last) result.push(ip.fromLong(current))
      }
    }
  }

  return result
}
github nswbmw / cli-chat / lib / cli-chat.js View on Github external
constructor ({ ip, port, subnetMask, username }) {
    this.ip = ip
    this.port = port
    this.username = username
    this.broadcastAddress = IP.subnet(ip, subnetMask).broadcastAddress
  }
github andrei-tatar / HAP.js / plugins / node / node_discover.js View on Github external
addresses.forEach(function (address) {
                if (address.internal || address.family != 'IPv4') return;
                var subnet = ip.subnet(address.address, address.netmask);
                broadcastAddresses.push(subnet.broadcastAddress);
            });
        }