Skip to content

Commit

Permalink
Request url for status code + get domains from text file
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardonunesdev committed Jul 31, 2017
1 parent c110d7e commit 3b01a9b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@ let dns = require('dns');
let ping = require('ping');
let Promise = require('bluebird');
let pad = require('pad');
let request = require('request');
let fs = require('fs');

let domains = require('./domains');
let domains = fs.readFileSync('domains.txt').toString().split("\n");

// TODO: Request url looking for status 200

function pingDomain(domain) {
return new Promise((resolve, reject) => {
dns.lookup(domain, (error, ip, family) => {
if (error) { return reject(error); }
ping.sys.probe(ip, (isAlive) => {
console.log(pad(ip, 15)+' - '+pad((isAlive ? 'up' : 'maybe down'), 10)+' - '+domain);
return resolve();
request('http://'+domain, (error2, response, body) => {
if (error2) { return reject(error2); }
console.log(pad(ip, 20)+' | '+pad((isAlive ? 'yes' : 'no'), 10)+' | '+pad(''+response.statusCode, 10)+' | '+domain);
return resolve();
});
});
});
});
}

console.log(pad('Ip', 20)+' | '+pad('Ping', 10)+' | '+pad('Status', 10)+' | '+'Domain');
console.log('-'.repeat(100));

Promise.map(domains, (domain) => {
return pingDomain(domain);
})
Expand Down

0 comments on commit 3b01a9b

Please sign in to comment.