-
Notifications
You must be signed in to change notification settings - Fork 14
Chikus sniffer revision #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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'); | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use var if you are not looking for exactly function-wide scope. It's better to be consistent and use let instead. Or maybe try to reduce amount of mutable global variables by passing them as arguments from function-to-function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and thanks