Skip to content

Instantly share code, notes, and snippets.

@indutny indutny/tls-estimate.js Secret
Last active Feb 3, 2016

Embed
What would you like to do?
var tls = require('tls');
var bloom = new (require('bloomfilter').BloomFilter)(
16 * 1024,
16
);
function ip() {
return ((Math.random() * 96 | 0) + 128) + '.' +
((Math.random() * 255 | 0) + 1) + '.' +
((Math.random() * 255 | 0) + 1) + '.' +
((Math.random() * 255 | 0) + 1);
}
var total = 0;
var secure = 0;
var parallel = process.argv[2] | 0;
function connect() {
var host = ip();
total++;
if (total % 1000 === 0)
console.log('%d / %d - %d %%', secure, total, secure / total * 100);
var c = tls.connect({
port: 443,
host: host,
rejectUnauthorized: false
}, function() {
// Ignore duplicates
var cert = c.getPeerCertificate();
if (cert && cert.fingerprint) {
if (!bloom.test(cert.fingerprint)) {
secure++;
bloom.add(cert.fingerprint);
}
}
c.destroy();
});
c.on('error', function(err) { });
c.once('close', function() {
connect();
});
c.setTimeout(5000, function() {
c.destroy();
});
}
for (var i = 0; i < parallel; i++)
connect();
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.