Skip to content

Instantly share code, notes, and snippets.

@dmh2000 dmh2000/time.js
Last active Oct 11, 2015

Embed
What would you like to do?
Assaf Arkin Date Challenge
// see results at https://labnotes.org/validate-your-assumptions/
var http=require('http');
var fs=require('fs');
// read the file and make a list of the hostnames
var list=fs.readFileSync('hostnames.txt').toString().split('\r\n');
// get from one host and process it
function get(a,i) {
if (i >= a.length) {
// DEBUG console.log('date not found');
return;
}
// get the host, trim it left and right in case the file has whitespace
var host = a[i].trimLeft().trimRight();
var url = "http://"+host+"/";
var next = i+1;
// get the host
http.get(url,function(res) {
if (res.headers.date) {
// date found, print it and quit
// DEBUG console.log(url);
var d =new Date(res.headers.date);
console.log(d.toISOString());
}
else {
// result did not have a date, get next host
// DEBUG console.log('no date : ' + url);
get(a,next);
}
}).on('error',function(e) {
// host not found or has no web server, ignore it and get the next one
// DEBUG console.log('no server : ' + url);
get(a,next);
});
}
get(list,0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.