How to use the ip.isPrivate 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 stanford-oval / thingengine-core / engine / node_modules / thingpedia / lib / base_device.js View on Github external
// if the device wants to be cloud-only, then it belongs to the cloud
        if (this.hasKind('cloud-only'))
            return this._ownerTier = Tier.CLOUD;

        // if the device wants to be phone-only, then it belongs to the phone
        if (this.hasKind('phone-only'))
            return this._ownerTier = Tier.PHONE;

        // online accounts belong to the cloud
        if (this.hasKind('online-account'))
            return this._ownerTier = Tier.CLOUD;

        // if this device is on (some) local network, it belongs to home
        if (this.state) {
            if ('host' in this.state && ip.isPrivate(this.state.host))
                return this._ownerTier = Tier.SERVER;
            if ('ip-address' in this.state && ip.isPrivate(this.state['ip-address']))
                return this._ownerTier = Tier.SERVER;
        }

        // anything else belongs to the phone
        // (in particular, this means that physical devices with a cloud
        // attachment, or an omlet ID, get handled by the phone, which ensures
        // privacy and makes everyone happy)
        return this._ownerTier = Tier.CLOUD;
    },
github origami-cms / cms / packages / core-server / src / Server.ts View on Github external
public async serve() {
    if (await checkPort(this._options.port!)) {
      throw new err.ErrorServerPortInUse(this._options.port!);
    }

    this._server = this.app.listen(this._options.port);
    const IP = ip.address();
    const host = ip.isPrivate(IP) ? 'localhost' : IP;

    info(
      'Server',
      'Is now running at',
      // tslint:disable-next-line no-http-string
      colors.yellow(`http://${host}:${this._options.port!.toString()}`)
    );

    // Run the default scripts
    await runScripts(this);
  }
github RiseVision / rise-node / modules / peers.js View on Github external
.filter(function (peer) {
			// Removing peers with private address or nonce equal to self
			if ((process.env['NODE_ENV'] || '').toUpperCase() === 'TEST') {
				return peer.nonce !== modules.system.getNonce() && (peer.os !== 'lisk-js-api');
			}
			return !ip.isPrivate(peer.ip) && peer.nonce !== modules.system.getNonce() && (peer.os !== 'lisk-js-api');
		}).value();
};
github ipfs-shipyard / ipfs-webui / src / bundles / peer-locations.js View on Github external
let isPrivate = false
  let isNearby = false
  let addr

  try {
    addr = maddr.nodeAddress()
  } catch (_) {
    // Might explode if maddr does not have an IP or cannot be converted
    // to a node address. This might happen if it's a relay. We do not print
    // or handle the error, otherwise we would get perhaps thousands of logs.
    return { isPrivate, isNearby }
  }

  // At this point, addr.address and publicIP must be valid IP addresses. Hence,
  // none of the calls bellow for ip library should fail.
  isPrivate = ip.isPrivate(addr.address)

  if (publicIP) {
    if (ip.isV4Format(addr.address)) {
      isNearby = ip.cidrSubnet(`${publicIP}/24`).contains(addr.address)
    } else if (ip.isV6Format(addr.address)) {
      isNearby = ip.cidrSubnet(`${publicIP}/48`).contains(addr.address) &&
        !ip.cidrSubnet('fc00::/8').contains(addr.address)
      // peerIP6 ∉ fc00::/8 to fix case of cjdns where IPs are not spatial allocated.
    }
  }

  return { isPrivate, isNearby }
}
github mmckegg / patchwork-next / lib / persistent-gossip / schedule.js View on Github external
function isLocal (e) {
  // don't rely on private ip address, because
  // cjdns creates fake private ip addresses.
  return ip.isPrivate(e.host) && e.source === 'local'
}
github w3c / Mobile-Checker / lib / checkremote.js View on Github external
function is_addr_local(addr) {
	if (ip.isPrivate(addr) == true) {
		return true;
	} else {
		return false;
	}
}
/**
github trainline / environment-manager / server / modules / administration / middlewares / LocalRequestsAuthorizer.js View on Github external
function middleware(req, res, next) {
  if (ip.isPrivate(req.ip)) {
    next();
  } else {
    res.status(401);
    res.send("Only local requests are allowed to this host.");
  }
}
github meboHQ / mebo / src / Inputs / Ip.js View on Github external
isPrivate(at=null){

    const value = this.valueAt(at);
    return nodeIp.isPrivate(value);
  }
github toyokazu / internet-visualizer2 / scripts / capture_sender.js View on Github external
var globalize = function(addr) {
  if (ip.isPrivate(addr)) {
    return global_ip;
  } else {
    return addr;
  }
}