How to use ipaddr - 10 common examples

To help you get started, we’ve selected a few ipaddr 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 F5Networks / f5-cloud-libs-gce / scripts / failover.js View on Github external
ipsFilter.forEach((ipFilter) => {
            // IP in filter array within range will constitute match
            let ipFilterAddr = ipFilter.address !== undefined ? ipFilter.address : ipFilter;
            ipFilterAddr = ipFilterAddr.split('/')[0];
            const ipFilterAddrParsed = ipaddr.parse(ipFilterAddr);
            if (ipFilterAddrParsed.match(ipAddrParsed)) {
                match = true;
            }
        });
        // Add IP to matched array if a match was found
github joyent / node-aperture / types / ip.js View on Github external
function eq(context, policy) {
    assert.string(context, 'context');
    policy = policy.split('/');
    var p_addr = ipaddr.parse(policy[0]);
    var p_bits = policy[1] || (p_addr.kind() === 'ipv6' ? 128 : 32);
    var c_addr = ipaddr.parse(context);
    var result = false;

    if (c_addr.kind() === p_addr.kind()) { // matching types
        result = c_addr.match(p_addr, p_bits);
    } else if (c_addr.kind() === 'ipv4') { // ipv4 == ipv6
        result = c_addr.toIPv4MappedAddress().match(p_addr, p_bits);
    } else if (c_addr.isIPv4MappedAddress()) { // ipv6 == ipv4
        result = c_addr.toIPv4Address().match(p_addr, p_bits);
    }

    return (result);
}
github scality / Arsenal / lib / ipCheck.js View on Github external
function parseIp(ip) {
    if (ipaddr.IPv4.isValid(ip)) {
        return ipaddr.parse(ip);
    }
    if (ipaddr.IPv6.isValid(ip)) {
        // also parses IPv6 mapped IPv4 addresses into IPv4 representation
        return ipaddr.process(ip);
    }
    // not valid ip address according to module, so return empty object
    // which will obviously not match a range of ip addresses that the parsedIp
    // is being tested against
    return {};
}
github linode / manager / packages / manager / src / features / linodes / LinodesDetail / LinodeNetworking / LinodeNetworking.tsx View on Github external
// Only keep addresses that:
    // 1. are part of an IPv6 range or pool
    // 2. have RDNS set
    if (
      !['ipv6/range', 'ipv6/pool'].includes(thisIP.type) ||
      thisIP.rdns === null
    ) {
      return;
    }

    // The ipaddr.js library throws an if it can't parse an IP address.
    // We'll wrap this in a try/catch block just in case something is malformed.
    try {
      // We need to typecast here so that the overloaded `match()` is typed
      // correctly.
      const addr = parseIP(thisIP.address) as IPv6;
      const parsedRange = parseIP(range) as IPv6;

      return addr.match(parsedRange, prefix);
    } catch {
      return false;
    }
  });
};
github Jigsaw-Code / outline-server / src / shadowbox / server / ip_util.ts View on Github external
export function anonymizeIp(ip: string): string {
  const addr = ipaddr.parse(ip);
  if (addr.kind() === 'ipv4') {
    // Replace last octet of ipv4 address with a 0.
    (addr as MyIPv4).octets[3] = 0;
    return addr.toString();
  } else {
    // Replace last 80 bits (5 groups of 4 hex characters) with 0s.
    for (let i = 3; i < 8; ++i) {
      (addr as MyIPv6).parts[i] = 0;
    }
    return addr.toNormalizedString();
  }
}
github joyent / node-aperture / types / ip.js View on Github external
function validate(input) {
    input = input.split('/');
    var addr = ipaddr.parse(input[0]);
    var upper;
    if (input.length > 1) {
        upper = addr.kind() === 'ipv6' ? 128 : 32;
        if (input[1] < 0 || input[1] > upper) {
            throw new Error('ip: prefix size must be between 0 and ' + upper);
        }
    }
}
github haraka / Haraka / connection.js View on Github external
if (ha_list.some((element, index, array) => {
            return ipaddr.parse(self.remote.ip).match(element[0], element[1]);
        })) {
            self.proxy.allowed = true;
github haraka / Haraka / plugins / early_talker.js View on Github external
exports.ip_in_list = function (ip) {
    const plugin = this;

    if (!plugin.whitelist) return false;

    const ipobj = ipaddr.parse(ip);

    for (let i = 0; i < plugin.whitelist.length; i++) {
        try {
            if (ipobj.match(plugin.whitelist[i])) {
                return true;
            }
        }
        catch (ignore) {
        }
    }
    return false;
}
github haraka / Haraka / plugins / greylist.js View on Github external
exports.ip_in_list = function (ip) {
    const plugin = this;
    const ipobj = ipaddr.parse(ip);

    const list = plugin.whitelist.ip;

    for (let i = 0; i < list.length; i++) {
        try {
            if (ipobj.match(list[i])) {
                return true;
            }
        }
        catch (e) {}
    }

    return false;
}
github awslabs / IsItOnAWS / lib / rangefinder.js View on Github external
module.exports.to16Bytes = function(address, ipv4) {
  var ip = ipaddr.parse(address);
  if (ipv4) {
    ip = ip.toIPv4MappedAddress();
  }
  return ip.toByteArray();
}

ipaddr

get computer's ipv4 address.

Unknown
Latest version published 4 years ago

Package Health Score

36 / 100
Full package analysis

Popular ipaddr functions