-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsniffer.js
More file actions
69 lines (66 loc) · 2.14 KB
/
Copy pathsniffer.js
File metadata and controls
69 lines (66 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const Net = require('net');
var host = '';
var lower_port = 0;
var higher_port = 65535;
var port_list = [];
var timeout = 300;
function check(host, port, callback) {
var socket = Net.createConnection(port, host);
var timer = setTimeout(function () {
socket.destroy();
callback(false);
}, timeout);
socket.once('connect', function () {
clearTimeout(timer);
socket.destroy();
process.stdout.write('.');
port_list.push(port);
callback(true);
});
socket.on('error', function () {
clearTimeout(timer);
callback(false);
});
}
function run_ports(){
check(host,lower_port, function next_check(result) {
if (lower_port == higher_port) {
if (port_list.length) {
process.stdout.write('\n'+port_list.join()+' ports are opened \n');
}
else {
process.stdout.write('No ports were found \n');
}
}
else {
check(host,++lower_port,next_check);
}
})
};
switch (process.argv[2]) {
case '--ports':
var ports = [2];
ports = process.argv[3].split('-');
lower_port = ports[0];
higher_port = ports[1];
if (process.argv[4] == '--host') {
host = process.argv[5];
process.stdout.write('Please verify your port range and your host name , for performance you can modify the variable timeout when you be in localhost, one suggestion use ping to know which will be the ideal timeout\n');
run_ports();
}
else {
process.stdout.write('Please type node sniffer.js --help to know the usage \n');
}
break;
case '--host':
host = process.argv[3];
process.stdout.write('Please verify your port range and your host name, for performance you can modify the variable timeout when you be in localhost, one suggestion use ping to know which will be the ideal timeout \n');
process.stdout.write('THanks you dont provide ports u will scan from 0 to 65535 \n');
run_ports();
break;
case '--help':
process.stdout.write('Please go to this website to read how to use this program \n https://github.com/kottans/backend/blob/master/tasks/network.md \n');
break;
default:
process.stdout.write('Please type node sniffer.js --help to know the usage \n');
}