How to use is-ip - 10 common examples

To help you get started, we’ve selected a few is-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 FabricLabs / fabric / src / matrix-to.js View on Github external
function isHostnameIpAddress(hostname) {
    hostname = getHostnameFromMatrixDomain(hostname);
    if (!hostname) return false;

    // is-ip doesn't want IPv6 addresses surrounded by brackets, so
    // take them off.
    if (hostname.startsWith("[") && hostname.endsWith("]")) {
        hostname = hostname.substring(1, hostname.length - 1);
    }

    return isIp(hostname);
}
github ZencashOfficial / arizen / app / zcommon.js View on Github external
function pingSecureNode() {
    if (isValidDomainName(settings.secureNodeFQDN)) {
        let ping = require('ping');
        const isIp = require('is-ip');

        let fqdnIsV6 = isIp.v6(settings.secureNodeFQDN);

        let cfg = {
            v6: fqdnIsV6,
        };

        let hosts = [settings.secureNodeFQDN];
        hosts.forEach(function (host) {
            ping.sys.probe(host, function (isAlive) {
                toggleLedHTML();
                if (ledWrapperExists()){
                    if (isAlive) {
                        document.getElementById("dotSNstatus").style.backgroundColor = "#34A853"; // green #34A853
                    } else {
                        document.getElementById("dotSNstatus").style.backgroundColor = "#EA4335"; // red #EA4335
                        document.getElementById("dotSNstatusRPC").style.backgroundColor = "#EA4335"; // red #EA4335
                    }
github shesek / spark-wallet / src / transport / tls.js View on Github external
const selfsigned = (name, dir) => {
  if (fs.existsSync(path.join(dir, 'key.pem'))) {
    const keyPem  = fs.readFileSync(path.join(dir, 'key.pem'))
        , certPem = fs.readFileSync(path.join(dir, 'cert.pem'))
        , cert    = forge.pki.certificateFromPem(certPem)
        , certDer = forge.asn1.toDer(forge.pki.certificateToAsn1(cert)).getBytes()
        , fprint  = forge.md.sha1.create().update(certDer).digest().toHex().match(/../g).join(':')

    console.log(`Loaded TLS certificate with fingerprint ${fprint} from ${ dir }`)
    return { key: keyPem, cert: certPem }
  }

  const extensions = [ ...defaultExt, {
    name: 'subjectAltName'
  , altNames: [ isIp(name) ? { type: 7, ip: name }
                           : { type: 2, value: name } ]
  } ]

  const pems = require('selfsigned').generate([ { name: 'commonName', value: name } ]
    , { extensions, keySize: 2048, algorithm: 'sha256' })

  !fs.existsSync(dir) && mkdirp.sync(dir)
  fs.writeFileSync(path.join(dir, 'key.pem'), pems.private)
  fs.writeFileSync(path.join(dir, 'cert.pem'), pems.cert)

  console.log(`Created TLS certificate with fingerprint ${ pems.fingerprint } in ${ dir }`)

  return { key: pems.private, cert: pems.cert }
}
github umaar / wiki-globe / index.js View on Github external
let location;

		try {
			data = JSON.parse(event.data);
		} catch (error) {
			console.log('Error parsing Wiki data', error);
			return;
		}

		if (data.type !== 'edit') {
			return;
		}

		const ipAddress = data.user;

		if (!data || !isIp(ipAddress)) {
			return;
		}

		try {
			location = await getLocation(ipAddress, data);
		} catch (error) {
			console.log('IP Location Error:', error);
			return;
		}

		if (!location || location.error) {
			console.log('IP Location Error:', {location});
			return;
		}

		const item = {
github greghesp / assistant-relay / client / src / views / override / index.js View on Github external
function submit() {
        if(isIP(ip)) {
            setReload()
        } else message.error("Not a valid IP address");
    }
github samuelmaddock / metastream / app / renderer / platform / swarm / ws-client-coordinator.ts View on Github external
const formatDestAddress = (ip: string) => {
  const hasPort = !isNaN(ip.split(':').pop() || ('' as any))
  if (isIp.v4(ip) && hasPort) {
    return ip
  }
  return urlFormat({ hostname: ip, port: WEBSOCKET_PORT_DEFAULT })
}
github hashicorp / nomad / ui / app / serializers / network.js View on Github external
normalize(typeHash, hash) {
    const ip = hash.IP;

    if (isIp.v6(ip)) {
      hash.IP = `[${ip}]`;
    }

    const reservedPorts = (hash.ReservedPorts || []).map(port => ({
      name: port.Label,
      port: port.Value,
      to: port.To,
      isDynamic: false,
    }));

    const dynamicPorts = (hash.DynamicPorts || []).map(port => ({
      name: port.Label,
      port: port.Value,
      to: port.To,
      isDynamic: true,
    }));
github berty / berty / client / react-native / tools / dashboard / node-geoip / lib / geoip.js View on Github external
function isIP (string) {
  if (isIpLib.v4(string)) return 4
  else if (isIpLib.v6(string)) return 6
  else return 0
}
github hashicorp / levant / vendor / github.com / hashicorp / nomad / ui / app / serializers / network.js View on Github external
normalize(typeHash, hash) {
    const ip = hash.IP;

    if (isIp.v6(ip)) {
      hash.IP = `[${ip}]`;
    }

    return this._super(...arguments);
  },
});

is-ip

Check if a string is an IP address

MIT
Latest version published 4 months ago

Package Health Score

73 / 100
Full package analysis

Popular is-ip functions