Skip to content

Instantly share code, notes, and snippets.

@suissa
Forked from kaiquewdev/portscan.js
Created August 6, 2012 14:46
Show Gist options
  • Save suissa/3274956 to your computer and use it in GitHub Desktop.
Save suissa/3274956 to your computer and use it in GitHub Desktop.
A port scan with node.js ( by Hacksparrow <http://www.hacksparrow.com> )
#!/usr/bin/env node
var net = require('net'),
host = 'localhost',
start = 1,
end = 10000,
timeout = 15000;
while ( start <= end ) {
var port = start;
(function ( port ) {
var s = new net.Socket();
s.setTimeout( timeout, function () {
s.destroy();
});
s.connect( port, host, function () {
console.log( 'OPEN: ' + port );
});
s.on( 'data', function ( data ) {
console.log( port + ': ' + data );
s.destroy();
});
s.on( 'error', function () {
s.destroy();
});
} ( port ));
start++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment