1.0.4 • Published 2 years ago

ping-ports v1.0.4

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

Ping-Ports

A Simple TCP & UDP ping tool

Table of Content

Installation

npm i ping-port

Usage

Simple Example

ESM

import ping from 'ping-port';

// TCP ping localhost:80
ping('localhost')
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    throw err;
  });

CJS

const ping = require('ping-port').default;

// TCP ping localhost:80
ping('localhost')
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    throw err;
  });
{
  "error": undefined,
  "type": "ping/tcp",
  "host": "localhost",
  "ip": "127.0.0.1",
  "ips": ["127.0.0.1"],
  "port": 80,
  "status": "open",
  "name": "http",
  "banner": "",
  "time": 2
}

Multiple Ports

// TCP ping to ports of localhost
ping('localhost:22,80-90,443,3306')
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    throw err;
  });
{
  "error": undefined,
  "type": "ping/tcp/scan",
  "host": "localhost",
  "ip": "127.0.0.1",
  "ips": ["127.0.0.1"],
  "ports": [22, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 443, 3306],
  "status": {
    "open": [22, 80, 3306],
    "reset": [],
    "close": [81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 443],
    "filtered": [],
    "error": []
  },
  "names": {
    "22": "ssh",
    "80": "http",
    "81": "unknown",
    "82": "xfer",
    "83": "mit-ml-dev",
    "84": "ctf",
    "85": "mit-ml-dev",
    "86": "mfcobol",
    "87": "unknown",
    "88": "kerberos",
    "89": "su-mit-tg",
    "90": "dnsix",
    "443": "https",
    "3306": "mysql"
  },
  "banners": { "22": "SSH-2.0-OpenSSH_8.9p1 Ubuntu-3" },
  "errors": {},
  "time": 2005
}

Ping TCP

// TCP ping to localhost:80
ping
  .tcp('localhost', 80)
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    throw err;
  });

Ping UDP

// UDP ping to localhost:68
ping
  .udp('localhost', 68)
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    throw err;
  });

Scan Ports

// TCP scan to ports of localhost
ping
  .scan('localhost', [21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 80, 443, 3306])
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    throw err;
  });

Scan UDP Ports

// UDP scan to ports of localhost
ping
  .scan('localhost', [67, 68, 161, 162, 163, 164], {
    protocol: 'udp',
  })
  .then((result) => {
    console.log(result);
  })
  .catch((err) => {
    throw err;
  });

Command Line

cd node_modules/ping-port
npm run query [host]:<port|ports> <...options>

options:   t: use tcp (default)   u: use udp   f: full log output   d <dns>: use specific dns server Example

npm run query example.com:@ t d 8.8.8.8
Running ping-port at 2022-09-24T13:15:21.226Z

query   : tcp/example.com:@
dns     : 8.8.8.8
ip      : 93.184.216.34

scan    : 1024 ports
open    : [80,443]
reset   : []
close   : [1119,1935]
filtered: 1020 ports

80      open    http
443     open    https
1119    close   bnetgame
1935    close   macromedia-fcs

API

query

ping(target, options);

target: string [host]:<port|ports> target ports: :80: target port 80 :80,90,100: target port 80, 90 and 100 :80-100: target port in range 80 to 100 :22,80-100,443: target port 22, port in range 80 to 100 and port 443 :@: target most used 1024 ports :*: target all ports (same as :1-65535) options: Object   options.protocol: string <tcp|udp>   options.filterBogon: boolean   options.dnsServer: string <server>

ping

ping.tcp(target, options);
ping.udp(host, port, options);

host: string [host] port: number <port> options: Object   options.timeout: number <miliseconds>   options.filterBogon: boolean   options.dnsServer: string <server>

scan

ping.scan(host, ports, options);

host: string [host] ports: Array <ports> options: Object   options.timeout: number <miliseconds>   options.chunk: number <chunk>   options.protocol: string <tcp|udp>   options.filterBogon: boolean   options.dnsServer: string <server>

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago