Socket
Socket
Sign inDemoInstall

is-reachable

Package Overview
Dependencies
29
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.3.1

61

index.js

@@ -9,2 +9,3 @@ 'use strict';

const pn = require('port-numbers');
const pTimeout = require('p-timeout');
const prependHttp = require('prepend-http');

@@ -15,42 +16,32 @@ const routerIps = require('router-ips');

const checkRedirection = url => {
return new Promise(resolve => {
got(url).then(res => {
const redirectHostname = (new URL(res.headers.location || '')).hostname;
if (routerIps.has(redirectHostname)) {
resolve(false);
}
resolve(true);
}).catch(() => resolve(false));
});
return got(url).then(res => {
return !routerIps.has((new URL(res.headers.location || '')).hostname);
}).catch(() => false);
};
function isTargetReachable(url) {
return new Promise(resolve => {
const uri = new URL(prependHttp(url));
const hostname = uri.hostname;
let protocol = uri.protocol;
const port = Number(uri.port) || pn.getPort(protocol.slice(0, -1)).port || 80;
const uri = new URL(prependHttp(url));
const hostname = uri.hostname;
let protocol = uri.protocol;
const port = Number(uri.port) || pn.getPort(protocol.slice(0, -1)).port || 80;
if (!/^[a-z]+:\/\//.test(url) && port !== 80 && port !== 443) {
protocol = pn.getService(port).name + ':';
if (!/^[a-z]+:\/\//.test(url) && port !== 80 && port !== 443) {
protocol = pn.getService(port).name + ':';
}
return pify(dns.lookup)(hostname).then(address => {
if (!address) {
return false;
}
pify(dns.lookup)(hostname).then(address => {
if (!address) {
resolve(false);
}
if (routerIps.has(address)) {
return false;
}
if (routerIps.has(address)) {
resolve(false);
}
if (protocol === 'http:' || protocol === 'https:') {
return checkRedirection(url);
}
if (protocol === 'http:' || protocol === 'https:') {
checkRedirection(url).then(resolve);
} else {
isPortReachable(port, {host: address}).then(resolve);
}
}).catch(() => resolve(false));
});
return isPortReachable(port, {host: address});
}).catch(() => false);
}

@@ -62,6 +53,4 @@

return new Promise(resolve => {
setTimeout(() => resolve(false), opts.timeout);
pAny(arrify(dests).map(isTargetReachable)).then(resolve);
});
const p = pAny(arrify(dests).map(isTargetReachable));
return pTimeout(p, opts.timeout).catch(() => false);
};
{
"name": "is-reachable",
"version": "2.3.0",
"version": "2.3.1",
"description": "Check if servers are reachable",

@@ -48,2 +48,3 @@ "license": "MIT",

"p-any": "^1.0.0",
"p-timeout": "^1.0.0",
"pify": "^2.3.0",

@@ -50,0 +51,0 @@ "port-numbers": "^1.1.53",

@@ -43,3 +43,3 @@ # is-reachable [![Build Status](https://travis-ci.org/sindresorhus/is-reachable.svg?branch=master)](https://travis-ci.org/sindresorhus/is-reachable)

Type: `string` `array`
Type: `string` `Array`

@@ -46,0 +46,0 @@ One or more targets to check. Can either be a full [URL](https://nodejs.org/api/url.html) like `https://hostname`, `hostname:port` or just `hostname`. When the protocol is missing from a target `http` is assumed.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc