npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-port-scan

v1.3.7

Published

scanner port, make tcp, udp, icmp, ping in javascript

Downloads

14

Readme

JS-PORT-SCAN FOR NODE.JS

Javascript-based library for port scanning, TCP calls, UDP, IPtracer, Discover host by ip and ip by host

INSTALL

npm install js-port-scan

HOW TO USE

const JsScan = require('js-port-scan')

Now you can instantiate a new Scanner class. This class extends the Scaner class that performs all the functionality

const jsScan =  new JsScan()

AVAILABLE FUNCTIONS

scanPorts

This method performs a scanner on a series of ports of a given host using the handShakeTcp method as the function center.

/**
* This method scanner a host with a interval for a inital end final given ports.
* A loopg was created to scanning the interval with handShakeTcp method.
 * Depens on your connetion and powers.
* @param {string} host ex: www.facebook.com
* @param {number} init initial (include) port
* @param {number} end final ( include ) final port
* @param {boolean} consoler display results in console
* @returns {Promise<Array<object>>}
*/
async scanPorts(host, init = 0, end = 1000, consoler = false)

The return of this function will be an array containing 1 object with the start and end date of the scanner an array of cobjects containing the ports that were successfully connected an array of objects containing ports that failed to connect successfully

return exemple:

[
 { init: '2023-03-23 15:27:18', end: '2023-03-23 15:28:00' },
  [
    {
      connected: true,
      msg: 'Established a TCP connection with www.youtube.com:80',        
      reason: ''
    }
  ],
  [
    {
      connected: false,
      msg: 'Erro to established a TCP connection with www.youtube.com:81',
      reason: 'ETIMEDOUT'
    },
    {
      connected: false,
      msg: 'Erro to established a TCP connection with www.youtube.com:82',
      reason: 'ETIMEDOUT'
    }
  ]
]

handShakeTcp

This class performs a TCP handshake call to validate a connection It is asynchronous and retrives an object.

/**
* this handShake make a tcp connection to a given host and port
* @param {number} port Port should be >= 0 and < 65536
* @param {string} host ip or dns
* @param {boolean} consoler display results in console
* @returns {Promise<{ connected: 0, msg: '', reason: '' }>}
*/
async handShakeTcp(port, host, consoler = false): 

Explanation of the return:

  • connected: true for success and false for problems connecting,
  • msg: Message generated by js-port-scaner about the process
  • reason: Filled in case an error occurs

udpScanner

This method is simple. Since UDP calls do not expect any return, this method will only return an error if there is a problem.

/**
* This method create a updCall. Upd call do not need return from the destination.
* So is not possible verify the return of the connection, only if we have error.
* @param {number} port
* @param {string} host
* @param {string} stringBytes
* @returns {Promise<any>}
*/
async udpScanner(port, host, stringBytes = null) 

tracer

This function provides a tracer to destinantion library-based nodejs-traceroute

/**
* This function create a trace untill the destination
* @param {string } host ex: www.facebook.com
* @param {boolean} consoler  if you want to display in console every tracer
* @returns {Promisse<Array<string>>}
*/

return exemple:

{"mesg":[{"trace":"{\"hop\":1,\"rtt1\":\"1 ms\",\"rtt2\":\"1 ms\",\"rtt3\":\"<1 ms\",\"ip\":\"localhost\"}"},
{"trace":"{\"hop\":2,\"rtt1\":\"15 ms\",\"rtt2\":\"1 ms\",\"rtt3\":\"1 ms\",\"ip\":\"10.255.255.5\"}"},
{"trace":"{\"hop\":3,\"rtt1\":\"2 ms\",\"rtt2\":\"3 ms\",\"rtt3\":\"2 ms\",\"ip\":\"198.19.0.225\"}"},
{"trace":"{\"hop\":4,\"rtt1\":\"5 ms\",\"rtt2\":\"3 ms\",\"rtt3\":\"2 ms\",\"ip\":\"198.18.0.33\"}"},
{"finish":"code 0"}]}

ipTracer

This method pings the destination and creates a tracer. it returns a string informed by the ping process

/**
* create ip ping tracer with a 4 call
* @param {string} host
* @param {number} ttl
* @returns {Promise<string>}
*/
async ipTracer(host)

return example:

Disparando 157.240.216.35 com 32 bytes de dados:
Resposta de 157.240.216.35: bytes=32 tempo=18ms TTL=54       
Resposta de 157.240.216.35: bytes=32 tempo=20ms TTL=54       
Resposta de 157.240.216.35: bytes=32 tempo=18ms TTL=54       
Resposta de 157.240.216.35: bytes=32 tempo=18ms TTL=54       

Estatisticas do Ping para 157.240.216.35:
Pacotes: Enviados = 4, Recebidos = 4, Perdidos = 0 (0% deperda),
Aproximar um n mero redondo de vezes em milissegundos:       
Minimo = 18ms, M ximo = 20ms, M dia = 18ms

getIpByHost

This method return an ip from a given host

/**
* This function retuns a ipv4 for a given host
* @param {string} host 
* @returns {Promise<string>}
*/
async getIpByHost(host) 

getHostByIp

This method return a host from a given IP

/**
* This function retuns a host for a given ip and port
* @param {string} host 
* @param {number} port
* @returns {Promise<string>}
*/
async getHostByIp(host, port)