How to use the isLoopback function from ip

Find comprehensive JavaScript ip.isLoopback code examples handpicked from public code repositorys.

97
98
99
100
101
102
103
104
105
106
107
  const [, info] = contact;
  const isValidAddr = ip.isV4Format(info.hostname) ||
                      ip.isV6Format(info.hostname) ||
                      ip.isPublic(info.hostname);
  const isValidPort = info.port > 0;
  const isAllowedAddr = ip.isLoopback(info.hostname) ? !!loopback : true;


  return isValidPort && isValidAddr && isAllowedAddr;
};

fork icon20
star icon1
watch icon0

+ 2 other calls in file

22
23
24
25
26
27
28
29
30
31
var getIps = function() {
	var interfaces = os.networkInterfaces();
	var all = Object.keys(interfaces).map(function (nic) {
		var addresses = interfaces[nic].filter(function (details) {
			details.family = details.family.toLowerCase();
			if (details.family !== 'ipv4' || ip.isLoopback(details.address)) {
				return false;
			}
			return true;
		});
fork icon4
star icon21
watch icon0

62
63
64
65
66
67
68
69
70
71
72
 * Tests if input is an IP address is a loopback ip address.
 * @param {string} ip
 * @returns {boolean}
 */
ipDash.isLoopbackIP = function (ip) {
  return nodeIp.isLoopback(ip);
};


/**
 * Returns the private ip address of the current running process.
fork icon0
star icon1
watch icon0

65
66
67
68
69
70
71
72
73
74
 * when this is called.
 */
const addresses = interfaces[nic].filter(function(details) {
  details.family = details.family.toLowerCase();
  details.ifname = nic;
  if (details.family !== family || ip.isLoopback(details.address)) {
    return false;
  } else if (!name) {
    return true;
  }
fork icon0
star icon0
watch icon0

190
191
192
193
194
195
196
197
198
199
200
201


  var isValidAddr = ip.isV4Format(contact.address) ||
                    ip.isV6Format(contact.address) ||
                    ip.isPublic(contact.address);
  var isValidPort = contact.port > 0;
  var isAllowedAddr = ip.isLoopback(contact.address) ? !!loopback : true;


  return isValidPort && isValidAddr && isAllowedAddr;
};

fork icon0
star icon0
watch icon0

79
80
81
82
83
84
85
86
87
88
89
router.get('/local', (req, res) => {
    res.json({
        local:
            process.env.SUBNET.split(',').some((v) => {
                return ip.cidrSubnet(v).contains(req.clientIp);
            }) || ip.isLoopback(req.clientIp),
    });
});


router.get('/roles', auth.block(auth.roles.admin), (req, res) => {
fork icon0
star icon0
watch icon0