-
-
Save indutny/e65982edcb2daa3acb1a to your computer and use it in GitHub Desktop.
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
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