How to use the ip.isLoopback 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 ssbc / ssb-server / plugins / gossip / schedule.js View on Github external
function isLocal (e) {
  // don't rely on private ip address, because
  // cjdns creates fake private ip addresses.
  // ignore localhost addresses, because sometimes they get broadcast.
  return !ip.isLoopback(e.host) && ip.isPrivate(e.host) && e.source === 'local'
}
github OriginTrail / ot-node / modules / service / rest-api-service.js View on Github external
server.use(cors.actual);
        server.use((request, response, next) => {
            const result = this.apiUtilities.authorize(request);
            if (result) {
                response.status(result.status);
                response.send({
                    message: result.message,
                });
                return;
            }
            return next();
        });

        // TODO: Temp solution to listen all adapters in local net.
        let serverListenAddress = this.config.node_rpc_ip;
        if (ip.isLoopback(serverListenAddress)) {
            serverListenAddress = '0.0.0.0';
        }

        // promisified server.listen()
        const startServer = () => new Promise((resolve, reject) => {
            server.listen(this.config.node_rpc_port, serverListenAddress, (err) => {
                if (err) {
                    reject(err);
                } else {
                    resolve();
                }
            });
        });

        await startServer(server, serverListenAddress);
        this.logger.notify(`API exposed at  ${server.url}`);
github OriginTrail / ot-node / modules / service / rest-api-controller.js View on Github external
server.use(cors.actual);
        server.use((request, response, next) => {
            const result = this.apiUtilities.authorize(request);
            if (result) {
                response.status(result.status);
                response.send({
                    message: result.message,
                });
                return;
            }
            return next();
        });

        // TODO: Temp solution to listen all adapters in local net.
        let serverListenAddress = this.config.node_rpc_ip;
        if (ip.isLoopback(serverListenAddress)) {
            serverListenAddress = '0.0.0.0';
        }

        // promisified server.listen()
        const startServer = () => new Promise((resolve, reject) => {
            server.listen(this.config.node_rpc_port, serverListenAddress, (err) => {
                if (err) {
                    reject(err);
                } else {
                    resolve();
                }
            });
        });

        await startServer(server, serverListenAddress);
        this.logger.notify(`API exposed at  ${server.url}`);
github lalcmellkmal / doushio / db.js View on Github external
m.rpush(pre + ':privs:' + priv, num);
		}
		else
			m.rpush(pre + ':posts', num);
	}
	else {
		// TODO: Add to alternate thread list?
		// set conditional hide?
		op = num;
		if (!view.immortal) {
			var score = expiry_queue_score(msg.time);
			var entry = num + ':' + tag_key(this.tag);
			m.zadd(expiry_queue_key(), score, entry);
		}
		/* Rate-limit new threads */
		if (ipUtils.isLoopback(ip))
			m.setex('ip:'+ip+':throttle:thread',
					config.THREAD_THROTTLE, op);
	}

	/* Denormalize for backlog */
	view.nonce = msg.nonce;
	view.body = body;
	if (msg.links)
		view.links = msg.links;
	extract(view);
	delete view.ip;

	var self = this;
	async.waterfall([
	function (next) {
		if (!msg.image)
github ssbc / secret-stack / core.js View on Github external
function parse(addr) {
  var parts = addr.split('~')[0].split(':')
  var protocol = parts[0], host = parts[1]
  return {
    protocol: protocol,
    group: (ip.isLoopback(host) || !host) ? 'loopback' : ip.isPrivate(host) ? 'local' : 'internet',
    host: host
  }
}
github jianxcao / ftl-node / src / tools.js View on Github external
var addresses = interfaces[nic].filter(function (details) {
			details.family = details.family.toLowerCase();
			if (details.family !== 'ipv4' || ip.isLoopback(details.address)) {
				return false;
			}
			return true;
		});
		return addresses.length ? addresses[0].address : undefined;
github stanford-oval / thingengine-core / lib / util / ip_address.js View on Github external
        return addresses.filter((a) => !ip.isLoopback(a) && a !== host);
    },
github w3c / insafe / lib / safe-url-input-checker.js View on Github external
checker.isAddressLocal = function(addr, cb) {
	if (cb) {
		if (ip.isPrivate(addr) || ip.isLoopback(addr)) cb(null, true);
		else cb(null, false);
	} else {
		if (ip.isPrivate(addr) || ip.isLoopback(addr)) return true;
		else return false;
	}
};
github mmckegg / patchwork-next / lib / persistent-gossip / schedule.js View on Github external
function isOffline (e) {
  if(ip.isLoopback(e.host)) return false
  return !hasNetwork()
}
github lalcmellkmal / doushio / db.js View on Github external
Y.reserve_post = function (op, ip, callback) {
	if (this.ident.readOnly)
		return callback(Muggle("Can't post right now."));
	var r = this.connect();
	if (ipUtils.isLoopback(ip))
		return reserve();

	var key = 'ip:' + ip + ':throttle:';
	var now = Date.now();
	var shortTerm = key + short_term_timeslot(now);
	var longTerm = key + long_term_timeslot(now);
	r.mget([shortTerm, longTerm], function (err, quants) {
		if (err)
			return callback(Muggle("Limiter failure.", err));
		if (quants[0] > config.SHORT_TERM_LIMIT ||
				quants[1] > config.LONG_TERM_LIMIT)
			return callback(Muggle('Reduce your speed.'));

		reserve();
	});