How to use the is-ip function in is-ip

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 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");
    }

is-ip

Check if a string is an IP address

MIT
Latest version published 9 months ago

Package Health Score

71 / 100
Full package analysis

Popular is-ip functions