Last active
January 24, 2020 10:53
-
-
Save LeoDJ/f133bd524d2216d1f88cc7fff9b3b899 to your computer and use it in GitHub Desktop.
Quick and dirty test to see which ports are whitelisted in a firewall
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 request = require('request'); | |
let blocked = [], open = [] | |
lastPort = 6000 | |
function pingPort(port) { | |
request('http://portquiz.net:' + port, function (err, res, body) { | |
//console.log(err, res, body) | |
if ((!err && res.statusCode == 200) || (err && err.code == 'HPE_INVALID_CONSTANT')) { | |
console.log('open:', port); | |
open.push(port); | |
} | |
else { | |
//console.log('blocked:', port); | |
blocked.push(port) | |
} | |
}); | |
} | |
for (i = 1; i < lastPort; i++) { | |
pingPort(i); | |
} | |
function numeric(a, b) { | |
return a - b; | |
} | |
function exitHandler(options, exitCode) { | |
if (options.cleanup) console.log('clean'); | |
if (exitCode || exitCode === 0) console.log(exitCode); | |
if (options.exit) process.exit(); | |
console.log("\n\n\n==== SCAN DONE! ===="); | |
console.log('Blocked:'); | |
console.dir(blocked.sort(numeric), { 'maxArrayLength': null }); | |
console.log('Open:'); | |
console.dir(open.sort(numeric), { 'maxArrayLength': null }); | |
} | |
//do something when app is closing | |
process.on('exit', exitHandler.bind(null, { cleanup: true })); | |
//catches ctrl+c event | |
process.on('SIGINT', exitHandler.bind(null, { exit: true })); | |
// catches "kill pid" (for example: nodemon restart) | |
process.on('SIGUSR1', exitHandler.bind(null, { exit: true })); | |
process.on('SIGUSR2', exitHandler.bind(null, { exit: true })); | |
//catches uncaught exceptions | |
process.on('uncaughtException', exitHandler.bind(null, { exit: true })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment