Skip to content

Instantly share code, notes, and snippets.

@rostegg
Created June 3, 2021 17:29
Show Gist options
  • Select an option

  • Save rostegg/5f2882238acca4ca58e653ba531d2b12 to your computer and use it in GitHub Desktop.

Select an option

Save rostegg/5f2882238acca4ca58e653ba531d2b12 to your computer and use it in GitHub Desktop.
Check if domains is alive
const domains = [
`sci-hub.ws`,
`sci-hub.ac`,
`sci-hub.biz`,
`sci-hub.gq`,
`sci-hub.ga`,
`sci-hub.io`,
`sci-hub.nu`,
`sci-hub.name`,
`sci-hub.is`,
`sci-hub.mn`,
`sci-hub.bz`,
`sci-hub.org`,
`sci-hub.tv`,
`mg.scihub.ltd`,
`sci-hub.nz`,
`sci-hub.la`,
`sci-hub.tw`,
`scihub.wikicn.top`,
`sci-hub.hk`,
`sci-hub.ren`,
`scihub.bban.top`,
`sci-hub.cc`,
`sci-hub.mksa.top`,
`sci-hub.shop`
]
function ping(url) {
function request_image(url) {
return new Promise(function(resolve, reject) {
const img = new Image();
img.onload = function() { resolve(true) };
img.onerror = function() { reject(false) };
img.src = `https:\\${url}/favicon.ico`;
});
}
return new Promise(function(resolve, reject) {
const response = function(isAlive) {
resolve( {url, isAlive});
};
request_image(url).then(response).catch(response);
setTimeout(function() { reject(Error('Timeout')); }, 5000);
});
}
const promises = domains.map((domain) => {
return ping(domain).catch(error => error)
})
Promise.all(promises)
.then(response => console.log(response))
.catch(error => console.log(`Error in executing ${error}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment