Skip to content

Instantly share code, notes, and snippets.

@p410n3
Last active December 8, 2017 10:38
Show Gist options
  • Save p410n3/f1356c91ef31c2a551f57c86cedf0381 to your computer and use it in GitHub Desktop.
Save p410n3/f1356c91ef31c2a551f57c86cedf0381 to your computer and use it in GitHub Desktop.
nodeJS: Find bad HTPP status
var fetchUrl = require("fetch").fetchUrl;
var fs = require('fs');
//Domain list from file
var domains = fs.readFileSync('domains.txt').toString().split("\n");
for (i = 0; i < domains.length; i++) {
fetchUrl(domains[i], function(error, meta){
//Without the try catch you encounter crashes due to weird async problmes (at least thats my guess)
try {
if (meta.status == 403 ||
meta.status == 404 ||
meta.status == 500 ||
meta.status == 502 ||
meta.status == 503 ) {
//Outputs only the domains with "bad" Status Codes
console.log(meta.finalUrl.toString() + ": "+ meta.status.toString());
}
throw 'excpetion';
}
catch(e) {
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment