How to use the ip-address.v6 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 GothAck / javascript-x-server / proxy.js View on Github external
, idStr;
  idBuf.fill(0);
  idBuf.writeUInt16BE(socket.remotePort, 16);
  if (net.isIPv4(socket.remoteAddress)) {
    idBuf.writeUInt8(4, 18);
    idBuf = socket.remoteAddress.split('.')
      .reduce(
          function (o, v, i) {
            o.writeUInt8(v, i);
            return o;
          }
        , idBuf
      );
  } else {
    idBuf.writeUInt8(6, 18);
    idBuf = (new ip.v6.Address(socket.remoteAddress)).parsedAddress
      .reduce(
          function (o, v, i) {
            o.writeUInt16BE(v, i * 2);
            return o;
          }
        , idBuf
      );
  }
  idStr = idBuf.toString('hex');

  this.client_sockets[idStr] = socket;
  this.connection.sendUTF('NEW ' + idStr);
  socket.on('close', function () {
    self.connection.sendUTF('END ' + idStr);
    delete self.client_sockets[idStr];
  });
github beaugunderson / mdns-swarm / dns-sd.js View on Github external
var addresses6 = addresses.filter(function (address) {
    if (address.family !== 'IPv6') {
      return false;
    }

    var v6 = new ip.v6.Address(address.address);

    return v6.isValid() &&
      (v6.getScope() === 'Global' || v6.getScope() === 'Reserved');
  }).map(function (address) {
    return {
github PaddeK / node-maxmind-db / lib / IPAddress.js View on Github external
'use strict';

var IPv6 = require('ip-address').v6;
var IPv4 = require('ip-address').v4;

exports.parseIPv4 = function parseIPv4(ip) {
    var v4Address = new IPv4.Address(ip);
    if (!v4Address.isValid()) {
        throw new Error("Invalid IPv4 address");
    }
    return v4Address.parsedAddress;
};

exports.parseIPv6 = function parseIPv6(ip) {
    var v6Address = new IPv6.Address(ip);
    if (!v6Address.isValid()) {
        throw new Error("Invalid IPv6 address");
    }
    return v6Address.parsedAddress;
github beaugunderson / mdns-swarm / mdns-swarm.js View on Github external
self.connectivityQueue.push(function (cb) {
        if (self.connectivity[service.host]) {
          return cb();
        }

        var v6 = new ip.v6.Address(address);

        var hostBase;

        if (v6.isValid()) {
          if (v6.getScope() !== 'Global') {
            self.debug('using hostname in favor of scoped IPv6 address');

            hostBase = 'http://' + service.hostname + ':' + service.port + '/';
          } else {
            hostBase = v6.href(service.port);
          }
        } else {
          hostBase = 'http://' + address + ':' + service.port + '/';
        }

        var url = hostBase + 'connectivity';

ip-address

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

MIT
Latest version published 7 months ago

Package Health Score

84 / 100
Full package analysis