Skip to content
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

Port sniffer #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Port sniffer #15

wants to merge 1 commit into from

Conversation

assmass13
Copy link

Port sniffer is developed.

Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@assmass13 good job!
However your commit affects demo files added by @AMashoshyna :

  • removes submissions/amashoshyna/port-sniffer/index.js
  • renames submissions/amashoshyna/port-sniffer/README.md

The above means these files will be no longer available for future contributors which is not really nice.

Please fix the issue.

Copy link
Member

@OleksiyRudenko OleksiyRudenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above is not a code review, however needs to be fixed before merge.

@OleksiyRudenko
Copy link
Member

@assmass13 thank you for updating the code base. Please avoid force pushing branches as this destroys the history.

@OleksiyRudenko OleksiyRudenko removed their request for review November 5, 2019 16:24
Copy link
Member

@lempiy lempiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool. See small requests bellow.

exit(0);
} else if (
args.indexOf('--host') === -1 ||
!args[args.indexOf('--host') + 1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we have

node sniffer.js --host --ports '80-90'

}

return args.reduce((result, item, index, arr) => {
if (item.indexOf('--') === 0 && arr[index + 1]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item.indexOf('--') === 0

=>

item.startsWith('--')

const parsedArgs = parseArgs(processArgs);
const address = await getAddress(parsedArgs['--host']);
const portLimits =
'--ports' in parsedArgs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pythonic approach ? 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful with that:

'length' in []
// true
'includes' in []
// true


return args.reduce((result, item, index, arr) => {
if (item.indexOf('--') === 0 && arr[index + 1]) {
return { ...result, [item]: arr[index + 1] };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe write to result object without useless symbols ?
{ ...result, [item.slice(2)]: arr[index + 1] }


function getPortLimits(portsRange) {
const arePortsValid = ports =>
ports.length === 2 &&
Copy link
Member

@lempiy lempiy Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to move it to module scope, cause this function doesn't use closure variables.

for (let port = startPort; port < endPort; port += 1) {
openPorts.push(scanAddressPort(address, port));
}
return Promise.all(openPorts).then(values => values.filter(Number.isFinite));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad idea, you may get a lot opened sockets at once, which, believe me, is not what we want to have. It may consume a lot of system resources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve it with batches or sequentially

});

socket.on('timeout', () => {
resolve(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a bad practice to return different datatypes from one function. In this case boolean and number. Use null for that.

async function getAddress(host) {
return new Promise((resolve, reject) => {
dns.lookup(host, (err, address) => {
if (err) reject(err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (err) return reject(err) ?


function exit(code) {
process.exit(code);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if you have helpers already you can do following ?

function writeFatal(str) {
    rocess.stdout.write(str);
    process.exit(1);
}

function writeSuccess(str) {
    rocess.stdout.write(str);
    process.exit(0);
}

function getPortLimits(portsRange) {
const arePortsValid = ports =>
ports.length === 2 &&
ports[0] >= defaultPortLimits.startPort &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, ports[0] never be lower then 0 cause you got ports.split('-')

const parsedArgs = parseArgs(processArgs);
const address = await getAddress(parsedArgs['--host']);
const portLimits =
'--ports' in parsedArgs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be careful with that:

'length' in []
// true
'includes' in []
// true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants