Last active
October 11, 2015 14:38
-
-
Save dmh2000/64d49eb81860826cccfe to your computer and use it in GitHub Desktop.
Assaf Arkin Date Challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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