How to use the ip-address.Address4 function in ip-address

To help you get started, we’ve selected a few ip-address 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 berty / berty / client / react-native / tools / dashboard / node-geoip / scripts / updatedb.js View on Github external
b.writeUInt32BE(eip[i], offset)
        offset += 4
      }
      b.writeUInt32BE(locId >>> 0, 32)

      lat = Math.round(parseFloat(fields[7]) * 10000)
      lon = Math.round(parseFloat(fields[8]) * 10000)
      area = parseInt(fields[9], 10)
      b.writeInt32BE(lat, 36)
      b.writeInt32BE(lon, 40)
      b.writeInt32BE(area, 44)
    } else {
      // IPv4
      bsz = 24

      rngip = new Address4(fields[0])
      sip = parseInt(rngip.startAddress().bigInteger(), 10)
      eip = parseInt(rngip.endAddress().bigInteger(), 10)
      locId = parseInt(fields[1], 10)
      locId = cityLookup[locId]
      b = Buffer.alloc(bsz)
      b.fill(0)
      b.writeUInt32BE(sip >>> 0, 0)
      b.writeUInt32BE(eip >>> 0, 4)
      b.writeUInt32BE(locId >>> 0, 8)

      lat = Math.round(parseFloat(fields[7]) * 10000)
      lon = Math.round(parseFloat(fields[8]) * 10000)
      area = parseInt(fields[9], 10)
      b.writeInt32BE(lat, 12)
      b.writeInt32BE(lon, 16)
      b.writeInt32BE(area, 20)
github bluesmoon / node-geoip / scripts / updatedb.js View on Github external
b.writeUInt32BE(eip[i], offset);
				offset += 4;
			}
			b.writeUInt32BE(locId>>>0, 32);
			
			lat = Math.round(parseFloat(fields[7]) * 10000);
			lon = Math.round(parseFloat(fields[8]) * 10000);
			area = parseInt(fields[9], 10);
			b.writeInt32BE(lat,36);
			b.writeInt32BE(lon,40);
			b.writeInt32BE(area,44);
		} else {
			// IPv4
			bsz = 24;

			rngip = new Address4(fields[0]);
			sip = parseInt(rngip.startAddress().bigInteger(),10);
			eip = parseInt(rngip.endAddress().bigInteger(),10);
			locId = parseInt(fields[1], 10);
			locId = cityLookup[locId];
			b = Buffer.alloc(bsz);
			b.fill(0);
			b.writeUInt32BE(sip>>>0, 0);
			b.writeUInt32BE(eip>>>0, 4);
			b.writeUInt32BE(locId>>>0, 8);

			lat = Math.round(parseFloat(fields[7]) * 10000);
			lon = Math.round(parseFloat(fields[8]) * 10000);
			area = parseInt(fields[9], 10);
			b.writeInt32BE(lat,12);
			b.writeInt32BE(lon,16);
			b.writeInt32BE(area,20);
github berty / berty / client / react-native / tools / dashboard / node-geoip / scripts / updatedb.js View on Github external
sip = utils.aton6(rngip.startAddress().correctForm())
        eip = utils.aton6(rngip.endAddress().correctForm())

        b = Buffer.alloc(bsz)
        for (i = 0; i < sip.length; i++) {
          b.writeUInt32BE(sip[i], i * 4)
        }

        for (i = 0; i < eip.length; i++) {
          b.writeUInt32BE(eip[i], 16 + i * 4)
        }
      } else {
        // IPv4
        bsz = 10

        rngip = new Address4(fields[0])
        sip = parseInt(rngip.startAddress().bigInteger(), 10)
        eip = parseInt(rngip.endAddress().bigInteger(), 10)

        b = Buffer.alloc(bsz)
        b.fill(0)
        b.writeUInt32BE(sip, 0)
        b.writeUInt32BE(eip, 4)
      }

      b.write(cc, bsz - 2)

      fs.writeSync(datFile, b, 0, bsz, null)
      if (Date.now() - tstart > 5000) {
        tstart = Date.now()
        process.stdout.write('\nStill working (' + lines + ') ...')
      }
github chill117 / geoip-native-lite / lib / data.js View on Github external
.map(function(line) {

			var data = line.split(',');

			if (!data || data.length < 2) {
				console.error('[ERROR]', 'Bad line:', line);
				return;
			}

			var geonameId = parseInt(data[1].replace(/"/g, ''));
			var ipv4Cidr = data[0].replace(/"/g, '');
			var ipv4Address = new Address4(ipv4Cidr);
			var ipv4StartAddress = ipv4Address.startAddress().correctForm();
			var ipv4EndAddress = ipv4Address.endAddress().correctForm();

			var block = {
				geoname_id: geonameId,
				ipv4_start_int: utils.ipv4ToInt(ipv4StartAddress)
			};

			if (ipv4StartAddress !== ipv4EndAddress) {

				block.ipv4_end_int = utils.ipv4ToInt(ipv4EndAddress);
			}

			countryBlocksIpv4.push(block);
		})
		.on('pipe', function() {
github HowNetWorks / uriteller / src / backend / lib / resolve.js View on Github external
exports.ipToASNs = function(ip) {
  if (net.isIP(ip)) {
    const ipv4 = new ipAddress.Address4(ip);
    if (ipv4.isValid()) {
      return lookup(ipv4.toArray().reverse().join(".") + ".origin.asn.cymru.com");
    }

    const ipv6 = new ipAddress.Address6(ip);
    if (ipv6.isValid()) {
      return lookup(ipv6.reverseForm({ omitSuffix: true }) + ".origin6.asn.cymru.com");
    }
  }
  return Promise.resolve([]);
};
github fourTheorem / ai-as-a-service / chapter7-8 / strategy-service / handler.js View on Github external
try {
    seedURL = new URL(seed)
    toURL = new URL(to)
  } catch (err) {
    log.debug({ err, seedURL, toURL }, `Rejecting due to invalid URL`)
    return false
  }

  if (!toURL.hostname) {
    log.debug(`Rejecting ${toURL} as invalid`)
    return false
  }
  if (seedURL.hostname === toURL.hostname) {
    return true
  }
  if (new Address4(toURL.hostname).isValid()) {
    log.debug(`Rejecting ${toURL} as it's an IP address`)
    return false
  }
  const parsedSeed = parseDomain(seedURL.hostname)
  const parsedTo = parseDomain(toURL.hostname)
  if (
    !parsedSeed ||
    !parsedTo ||
    parsedSeed.domain !== parsedTo.domain ||
    parsedSeed.tld !== parsedTo.tld
  ) {
    log.debug(`Rejecting ${to} from a different domain to seed ${seed}`)
    return false
  }
  return true
}
github validitylabs / hopr / src / network / natTraversal / base / udp4.js View on Github external
const addrs = groupBy(multiaddrs, ma => {
            const addr = new Address4(ma.toOptions().host)

            if (addr.isInSubnet(new Address4('127.0.0.1/8'))) return 'loopback'

            if (
                addr.isInSubnet(new Address4('10.0.0.0/8')) ||
                addr.isInSubnet(new Address4('172.16.0.0/12')) ||
                addr.isInSubnet(new Address4('192.168.0.0/16'))
            )
                return 'local'

            if (addr.isInSubnet(new Address4('169.254.0.0/16'))) return 'link-local'

            return 'global'
        })
github jen20 / pulumi-aws-vpc / nodejs / dist / subnetDistributor.js View on Github external
function cidrSubnetV4(ipRange, newBits, netNum) {
    const ipAddress = require("ip-address");
    const BigInteger = require("jsbn").BigInteger;
    const ipv4 = new ipAddress.Address4(ipRange);
    if (!ipv4.isValid()) {
        throw new Error(`Invalid IP address range: ${ipRange}`);
    }
    const newSubnetMask = ipv4.subnetMask + newBits;
    if (newSubnetMask > 32) {
        throw new Error(`Requested ${newBits} new bits, but ` +
            `only ${32 - ipv4.subnetMask} are available.`);
    }
    const addressBI = ipv4.bigInteger();
    const newAddressBase = Math.pow(2, 32 - newSubnetMask);
    const netNumBI = new BigInteger(netNum.toString());
    const newAddressBI = addressBI.add(new BigInteger(newAddressBase.toString()).multiply(netNumBI));
    const newAddress = ipAddress.Address4.fromBigInteger(newAddressBI).address;
    return `${newAddress}/${newSubnetMask}`;
}
/**
github jen20 / pulumi-aws-vpc / nodejs / src / subnetDistributor.ts View on Github external
function cidrSubnetV4(ipRange: string, newBits: number, netNum: number): string {
    const ipAddress = require("ip-address");
    const BigInteger = require("jsbn").BigInteger;

    const ipv4 = new ipAddress.Address4(ipRange);
    if (!ipv4.isValid()) {
        throw new Error(`Invalid IP address range: ${ipRange}`);
    }

    const newSubnetMask = ipv4.subnetMask + newBits;
    if (newSubnetMask > 32) {
        throw new Error(`Requested ${newBits} new bits, but ` +
            `only ${32 - ipv4.subnetMask} are available.`);
    }

    const addressBI = ipv4.bigInteger();
    const newAddressBase = Math.pow(2, 32 - newSubnetMask);
    const netNumBI = new BigInteger(netNum.toString());

    const newAddressBI = addressBI.add(new BigInteger(newAddressBase.toString()).multiply(netNumBI));
    const newAddress = ipAddress.Address4.fromBigInteger(newAddressBI).address;
github jen20 / pulumi-aws-vpc / nodejs / dist / cidr.js View on Github external
function subnetV4(ipRange, newBits, netNum) {
    const ipAddress = require("ip-address");
    const BigInteger = require("jsbn").BigInteger;
    const ipv4 = new ipAddress.Address4(ipRange);
    if (!ipv4.isValid()) {
        throw new Error(`Invalid IP address range: ${ipRange}`);
    }
    const newSubnetMask = ipv4.subnetMask + newBits;
    if (newSubnetMask > 32) {
        throw new Error(`Requested ${newBits} new bits, but ` +
            `only ${32 - ipv4.subnetMask} are available.`);
    }
    const addressBI = ipv4.bigInteger();
    const newAddressBase = Math.pow(2, 32 - newSubnetMask);
    const netNumBI = new BigInteger(netNum.toString());
    const newAddressBI = addressBI.add(new BigInteger(newAddressBase.toString()).multiply(netNumBI));
    const newAddress = ipAddress.Address4.fromBigInteger(newAddressBI).address;
    return `${newAddress}/${newSubnetMask}`;
}
exports.subnetV4 = subnetV4;

ip-address

A library for parsing IPv4 and IPv6 IP addresses in node and the browser.

MIT
Latest version published 1 month ago

Package Health Score

85 / 100
Full package analysis