Git Product home page Git Product logo

tcpie's Introduction

tcpie

Ping any TCP port

tcpie is a tool to measure latency and verify the reliabilty of a TCP connection. It does so by initiating a handshake followed by an immediately termination of the socket. While many existing tools require raw socket access, tcpie runs fine in user space. An API for use as a module is also provided.

CLI

Installation

$ npm i -g tcpie

Example

$ tcpie -c 5 google.com 443
TCPIE google.com (188.21.9.120) port 443
connected to google.com:443 seq=1 srcport=59053 time=12.9 ms
connected to google.com:443 seq=2 srcport=59054 time=10.0 ms
connected to google.com:443 seq=3 srcport=59055 time=10.1 ms
connected to google.com:443 seq=4 srcport=59056 time=11.4 ms
connected to google.com:443 seq=5 srcport=59057 time=10.4 ms

--- google.com tcpie statistics ---
5 handshakes attempted, 5 succeeded, 0% failed
rtt min/avg/max/stdev = 10.012/10.970/12.854/1.190 ms

API

Usage

import {tcpie} from "tcpie";
const pie = tcpie("google.com", 443, {count: 10, interval: 500, timeout: 2000});

pie.on("connect", function(stats) {
  console.info("connect", stats);
}).on("error", function(err, stats) {
  console.error(err, stats);
}).on("timeout", function(stats) {
  console.info("timeout", stats);
}).on("end", function(stats) {
  console.info(stats);
  // -> {
  // ->   sent: 10,
  // ->   success: 10,
  // ->   failed: 0,
  // ->   target: { host: "google.com", port: 443 }
  // -> }
}).start();

tcpie(host, [port], [options])

  • host string : the destination host name or IP address. Required.
  • port number : the destination port. Default: 22.
  • opts object : options for count, interval and timeout. Defaults: Infinity, 1000, 3000.

tcpie#start()

Start connecting

tcpie#stop()

Stops connecting

options object

  • count number : the number of connection attempts in milliseconds (default: Infinity).
  • interval number : the interval between connection attempts in milliseconds (default: 1000).
  • timeout number : the connection timeout in milliseconds (default: 3000).

Events

  • connect : Arguments: stats. Connection attempt succeeded.
  • timeout : Arguments: stats. Connection attempt ran into the timeout.
  • error : Arguments: err, stats. Connection attempt failed.
  • end : Arguments: stats. All connection attempts have finished.

stats argument properties

  • sent number : number of total attempts made.
  • success number : number of successfull attempts.
  • failed number : number of failed attempts.
  • target object : target details: host and port.

The following properties are present on all events except end:

  • rtt number : roundtrip time in milliseconds. undefined if failed.
  • socket object : socket details: localAddress, localPort, remoteAddress, remotePort.

© silverwind, distributed under BSD licence

tcpie's People

Contributors

dependabot[bot] avatar silverwind avatar zeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tcpie's Issues

Speed up flood mode

setTimeout(fn, 0)is considerably slower than process.nextTick(fn) and setImmediate(fn). Both have drawbacks which I have to evaluate first.

srcport=undefined one some timeouts

Looks like under some conditions, timeouts don't print a srcport, will have to investigate.

connected to host:21 seq=767 srcport=37407 time=22.8 ms
connected to host:21 seq=768 srcport=37411 time=28.7 ms
connected to host:21 seq=769 srcport=37412 time=15.8 ms
timeout connecting to host:21 seq=770 srcport=undefined
connected to host:21 seq=771 srcport=37414 time=21.8 ms
connected to host:21 seq=772 srcport=37416 time=19.2 ms
connected to host:21 seq=773 srcport=37417 time=7.9 ms
connected to host:21 seq=774 srcport=37421 time=14.9 ms

can't seem to use pie.start() a second time.

Love this module.. I'm trying to setup a reusable class called Ping with module API for an app I'm building.. my goal is to ping a host 4 times quickly, wait 5 minutes, and ping it again. It would seem that after the first pie.start() - I'm unable to run pie.start() again unless a create a new instance.

Not sure if this has long run memory implications or not, just seems like I should be able to run it again. I'm just dabbling at this point for fun - code is here - https://github.com/msudol/node-ping-monitor

ping stop method

What is about to implement stop method?
I dont know how many times I will ping my server for response and I want to stop ping when it answers.
I make it this way:

pie.on("connect", () =>{
    pie.opts.count = 0;//to stop ping
    // great code
})

I think that pie.stop() method will be more semantic

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.