Created
March 29, 2017 14:54
-
-
Save lapo-luchini/7550b6a925a4743e859d83a9a0f71c8a to your computer and use it in GitHub Desktop.
node script to check expiration date of a list of https domains
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
#!/usr/bin/env node | |
//jshint node: true, esversion: 6, strict: global, indent: 4, immed: true, undef: true, sub: true, newcap: false | |
'use strict'; | |
const fs = require('fs'), | |
readline = require('readline'), | |
https = require('https'), | |
now = Date.now(), | |
c = { | |
reset: '\x1b[0m', | |
blue: '\x1b[34m', | |
yellow: '\x1b[33m', | |
red: '\x1b[31m', | |
}, | |
list = __dirname + '/domains.txt'; | |
function pad(len, str) { | |
if (str.length > len) | |
return str.slice(0, len - 1) + '\u2026'; | |
return str + ' '.repeat(len - str.length); | |
} | |
function lpad(len, str) { | |
if (str.length > len) | |
return '\u2026' + str.slice(0, len - 1); | |
return ' '.repeat(len - str.length) + str; | |
} | |
if (!fs.existsSync(list)) { | |
console.log('Create a file named domains.txt with the list of domains to check, one per line.'); | |
process.exit(1); | |
} | |
let max = 0; | |
readline.createInterface({ | |
input: fs.createReadStream(list) | |
}).on('line', (dom) => { | |
max = Math.max(max, dom.length); | |
}).on('close', () => { | |
++max; | |
console.log(c.blue + pad(max, 'Dominio'), pad(10, 'Date'), lpad(9, 'Expires') + ' ', pad(30, 'Issuer'), 'Subject Alternative Name' + c.reset); | |
readline.createInterface({ | |
input: fs.createReadStream(list) | |
}).on('line', (dom) => { | |
dom = dom.trim(); | |
if (!dom.length) | |
return; | |
try { | |
https.get('https://' + dom + '/', function (res) { | |
const cert = res.socket.getPeerCertificate(), | |
date = new Date(cert.valid_to), | |
days = Math.floor((date - now) / 86400000), | |
color = days > 60 ? '' : days > 22 ? c.yellow : c.red; | |
console.log(pad(max, dom), color + date.toISOString().slice(0, 10), lpad(9, days + ' days') + c.reset + ' ', pad(30, cert.issuer.CN), cert.subjectaltname); | |
}).on('error', (e) => { | |
console.log(pad(max, dom), c.red + 'ERROR' + c.reset); | |
}); | |
} catch (e) { | |
console.log(pad(max, dom), c.red + 'ERROR' + c.reset); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment