How to use the ip.isV4Format 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 ipfs-shipyard / ipfs-webui / src / bundles / peer-locations.js View on Github external
try {
    addr = maddr.nodeAddress()
  } catch (_) {
    // Might explode if maddr does not have an IP or cannot be converted
    // to a node address. This might happen if it's a relay. We do not print
    // or handle the error, otherwise we would get perhaps thousands of logs.
    return { isPrivate, isNearby }
  }

  // At this point, addr.address and publicIP must be valid IP addresses. Hence,
  // none of the calls bellow for ip library should fail.
  isPrivate = ip.isPrivate(addr.address)

  if (publicIP) {
    if (ip.isV4Format(addr.address)) {
      isNearby = ip.cidrSubnet(`${publicIP}/24`).contains(addr.address)
    } else if (ip.isV6Format(addr.address)) {
      isNearby = ip.cidrSubnet(`${publicIP}/48`).contains(addr.address) &&
        !ip.cidrSubnet('fc00::/8').contains(addr.address)
      // peerIP6 ∉ fc00::/8 to fix case of cjdns where IPs are not spatial allocated.
    }
  }

  return { isPrivate, isNearby }
}
github qiushi123 / xiaochengxu_demos / 014云开发实现小程序支付 / cloud / pay / node_modules / urllib / lib / urllib.js View on Github external
responseTimer = null;
            var msg = 'Response timeout for ' + responseTimeout + 'ms';
            var errorName = 'ResponseTimeoutError';
            __err = new Error(msg);
            __err.name = errorName;
            __err.requestId = reqId;
            debug('ResponseTimeout: Request#%d %s %s: %s, connected: %s', reqId, url, __err.name, msg, connected);
            abortRequest();
        }, responseTimeout);
    }

    if (args.checkAddress) {
        var hostname = parsedUrl.hostname;
        // if request hostname is ip, custom lookup wont excute
        var family = null;
        if (ip.isV4Format(hostname)) {
            family = 4;
        } else if (ip.isV6Format(hostname)) {
            family = 6;
        }
        if (family) {
            if (!args.checkAddress(hostname, family)) {
                var err = new Error('illegal address');
                err.name = 'IllegalAddressError';
                err.hostname = hostname;
                err.ip = hostname;
                err.family = family;
                return done(err);
            }
        }
    }
github lukasroegner / homebridge-nello / CameraSource.js View on Github external
srtp_salt: srtpSalt
        }

        response['audio'] = audioResp

        sessionInfo['audio_port'] = targetPort
        sessionInfo['audio_srtp'] = Buffer.concat([srtpKey, srtpSalt])
        sessionInfo['audio_ssrc'] = ssrc
    }

    let currentAddress = ip.address()
    var addressResp = {
        address: currentAddress
    }

    if (ip.isV4Format(currentAddress)) {
        addressResp['type'] = 'v4'
    } else {
        addressResp['type'] = 'v6'
    }

    response['address'] = addressResp
    this.pendingSessions[this.hap.uuid.unparse(sessionID)] = sessionInfo

    callback(response)
}
github mozilla / fxa-auth-db-mysql / lib / db / mysql.js View on Github external
function ipHmac(key, uid, addr) {
    if (ip.isV4Format(addr)) {
      addr = '::' + addr
    }
    addr = ip.toBuffer(addr)

    var hmac = crypto.createHmac('sha256', key)
    hmac.update(uid)
    hmac.update(addr)

    return hmac.digest()
  }
github mappum / bitcoin-protocol / src / dataTypes.js View on Github external
function encode (addr, buf) {
    if (ip.isV4Format(addr)) {
      IPV4_PREFIX.copy(buf)
      ip.toBuffer(addr, buf, 12)
    } else if (ip.isV6Format(addr)) {
      ip.toBuffer(addr, buf)
    } else {
      throw new Error('Invalid IP address value')
    }
  },
  function decode (buf, d) {
github jensweigele / ioBroker.yahka / yahka.homekit-ipcamera.js View on Github external
var audioResp = {
                port: targetPort,
                ssrc: 1,
                srtp_key: srtp_key,
                srtp_salt: srtp_salt
            };
            response["audio"] = audioResp;
            sessionInfo["audio_port"] = targetPort;
            sessionInfo["audio_srtp"] = Buffer.concat([srtp_key, srtp_salt]);
            sessionInfo["audio_ssrc"] = 1;
        }
        var currentAddress = ip.address();
        var addressResp = {
            address: currentAddress
        };
        if (ip.isV4Format(currentAddress)) {
            addressResp["type"] = "v4";
        }
        else {
            addressResp["type"] = "v6";
        }
        response["address"] = addressResp;
        this.pendingSessions[hap_nodejs_1.uuid.unparse(sessionID, 0)] = sessionInfo;
        callback(response);
    };
    THomeKitIPCamera.prototype.handleStreamRequest = function (request) {
github latysheff / node-sctp / lib / sockets.js View on Github external
  addresses = addresses.filter(address => ip.isV4Format(address))
  return addresses