Socket
Socket
Sign inDemoInstall

is-reachable

Package Overview
Dependencies
10
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.3 to 2.4.0

41

index.js
'use strict';
const dns = require('dns');
const net = require('net');
const arrify = require('arrify');

@@ -14,35 +15,37 @@ const got = require('got');

const checkRedirection = url => {
return got(url).then(res => {
return !routerIps.has((new URL(res.headers.location || '')).hostname);
const checkRedirection = target => {
return got(target, {rejectUnauthorized: false}).then(res => {
const url = new URL(res.headers.location || 'x://x');
return !routerIps.has(url.hostname);
}).catch(() => false);
};
function isTargetReachable(url) {
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;
function isTargetReachable(target) {
const url = new URL(prependHttp(target));
url.port = Number(url.port) || pn.getPort(url.protocol.slice(0, -1)).port || 80;
if (!/^[a-z]+:\/\//.test(url) && port !== 80 && port !== 443) {
protocol = pn.getService(port).name + ':';
if (!/^[a-z]+:\/\//.test(target)) {
url.protocol = pn.getService(url.port).name + ':';
}
return pify(dns.lookup)(hostname).then(address => {
if (!address) {
return getAddress(url.hostname).then(address => {
if (!address || routerIps.has(address)) {
return false;
}
if (routerIps.has(address)) {
return false;
if (url.protocol === 'http:' || url.protocol === 'https:') {
return checkRedirection(url.toString());
}
if (protocol === 'http:' || protocol === 'https:') {
return checkRedirection(url);
}
return isPortReachable(port, {host: address});
return isPortReachable(url.port, {host: address});
}).catch(() => false);
}
function getAddress(hostname) {
if (net.isIP(hostname)) {
return Promise.resolve(hostname);
}
return pify(dns.lookup)(hostname);
}
module.exports = (dests, opts) => {

@@ -49,0 +52,0 @@ opts = opts || {};

{
"name": "is-reachable",
"version": "2.3.3",
"version": "2.4.0",
"description": "Check if servers are reachable",

@@ -45,11 +45,11 @@ "license": "MIT",

"arrify": "^1.0.1",
"got": "^7.1.0",
"got": "^8.0.3",
"is-port-reachable": "^2.0.0",
"p-any": "^1.1.0",
"p-timeout": "^1.2.0",
"p-timeout": "^2.0.1",
"pify": "^3.0.0",
"port-numbers": "^2.0.3",
"prepend-http": "^1.0.4",
"port-numbers": "^2.0.20",
"prepend-http": "^2.0.0",
"router-ips": "^1.0.0",
"url-parse": "^1.1.9"
"url-parse": "^1.2.0"
},

@@ -56,0 +56,0 @@ "devDependencies": {

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

Timeout in milliseconds after which a request is considered failed. Default: `5000.
Timeout in milliseconds after which a request is considered failed. Default: `5000`.

@@ -58,0 +58,0 @@ ## Contributors

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