is-reachable
Advanced tools
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 |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
6419
67
2
+ Added@sindresorhus/is@0.7.0(transitive)
+ Addedcacheable-request@2.1.4(transitive)
+ Addedclone-response@1.0.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addedfrom2@2.3.0(transitive)
+ Addedgot@8.3.2(transitive)
+ Addedhttp-cache-semantics@3.8.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinto-stream@3.1.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjson-buffer@3.0.0(transitive)
+ Addedkeyv@3.0.0(transitive)
+ Addedlowercase-keys@1.0.0(transitive)
+ Addednormalize-url@2.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedp-cancelable@0.4.1(transitive)
+ Addedp-is-promise@1.1.0(transitive)
+ Addedp-timeout@2.0.1(transitive)
+ Addedprepend-http@2.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedquery-string@5.1.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedresponselike@1.0.2(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsort-keys@2.0.0(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedurl-parse-lax@3.0.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedgot@7.1.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedp-cancelable@0.3.0(transitive)
- Removedp-timeout@1.2.1(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedurl-parse-lax@1.0.0(transitive)
Updatedgot@^8.0.3
Updatedp-timeout@^2.0.1
Updatedport-numbers@^2.0.20
Updatedprepend-http@^2.0.0
Updatedurl-parse@^1.2.0