Socket
Socket
Sign inDemoInstall

tcp-ping-port

Package Overview
Dependencies
4
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tcp-ping-port

A simple TCP ping utility to ping a port of an IP or domain


Version published
Weekly downloads
125
decreased by-25.15%
Maintainers
1
Install size
1.85 MB
Created
Weekly downloads
 

Readme

Source

tcp-ping-port

A simple TCP ping utility to ping a port of an IP or domain.

NPM version Release Status Build Status Coverage Status

Table of contents


Benefits


Following are the pros and cons of this package compared to the regular ping

Pros

  • Can be used with Amazon Lambda functions and Aazure functions.
    Regular ping uses ICMP protocol which is not permitted by AWS/Azure functions
  • TCP packets have higher priorty than ICMP packets
  • It can ping a particular port
  • It can work even if ICMP is disabled

Cons

  • Higher data usage

    ProtocolSend (B))Receive (B)Total (B)Data saving
    TCP2281263540%
    ICMP989819645%

    The numbers are based on data reported by Wireshark

    TCP Ping
    No.TimeSourceDestinationProtocolLengthInfo
    10.000000x.x.x.xy.y.y.yDNS70Standard query 0xfe55 A google.com
    20.000393y.y.y.yx.x.x.xDNS86Standard query response 0xfe55 A google.com A 172.217.165.14
    30.001364x.x.x.x172.217.165.14TCP6649985 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1
    40.012339172.217.165.14x.x.x.xTCP6680 → 49985 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1430 SACK_PERM=1 WS=256
    50.012412x.x.x.x172.217.165.14TCP5449985 → 80 [ACK] Seq=1 Ack=1 Win=262912 Len=0
    60.013110x.x.x.x172.217.165.14TCP5449985 → 80 [FIN, ACK] Seq=1 Ack=1 Win=262912 Len=0
    70.024927172.217.165.14x.x.x.xTCP6080 → 49985 [FIN, ACK] Seq=1 Ack=2 Win=65536 Len=0
    80.024987x.x.x.x172.217.165.14TCP5449985 → 80 [ACK] Seq=2 Ack=2 Win=262912 Len=0
    ICMP ping
    No.TimeSourceDestinationProtocolLengthInfo
    10.000000x.x.x.xy.y.y.yDNS70Standard query 0xff9e A google.com
    20.003286y.y.y.yx.x.x.xDNS86Standard query response 0xff9e A google.com A 172.217.165.14
    30.040291x.x.x.x172.217.165.14ICMP98Echo (ping) request id=0x0279, seq=1/256, ttl=128 (reply in 6)
    40.064258172.217.165.14x.x.x.xICMP98Echo (ping) reply id=0x0279, seq=1/256, ttl=112 (request in 5)

    NOTE: The first 2 DNS resolution calls are same in both cases for IPv4 and are not included in the total data usagage.

back to top

Installation


$ npm install tcp-ping-port --save

back to top

How to use


Simple examples

const { tcpPingPort } = require("tcp-ping-port")

tcpPingPort("google.com").then(online => {
    // ....
})

With additional options

const { tcpPingPort } = require("tcp-ping-port")
const dns = require('dns')
const options = { 
    socketTimeout: 11000, 
    dnsTimeout: 10000,
    dnsServers: '8.8.8.8',  // google DNS
}
tcpPingPort("google.com", 80, options).then(online => {
    // ....
})

back to top

Dependencies

  • dns-fast-resolver - to resolve multiple domains at the same time and to handle any errors while resolving the domain name. Also, to skip the whole dns resolution if host name is an IP address.
  • lodash
  • maketype

back to top

API

tcpPingPort(hostname[, port, options, resolver])

Attemps to open and close TCP connection

  • hostname <string> Host name or an IP address to try to connect to
  • port <number> Port number
  • options <Object> Socket and Resolver options
    • socketTimeout <integer> Number of miliseconds to wait before the resolving request is canceled. Default value 4000 (4s).
    • dnsTimeout <integer> Number of miliseconds to wait before the resolving request is canceled. Default value 4000 (4s).
      Usefull for rare cases when hostnames may need more than default 4 seconds to be resolved.
    • dnsServers <string[]> Array of RFC 5952 formatted addresses. (Example: ['4.4.4.4', '[2001:4860:4860::8888]', '4.4.4.4:1053', '[2001:4860:4860::8888]:1053'])
  • returns <Promise> Promise that will return online status of host
    • True - when host is online and TCP connection is successfully opened and closed
    • False - when host name is not resolved or it failed to open a TCP connection

back to top

Testing

Run all tests

$ npm test

Run ping "google.com:80" test

$ npm run unit-test -- --grep "google.com:80"

back to top

Keywords

FAQs

Last updated on 19 Nov 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc