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

@juit/lib-ping

v1.2.2

Published

Rootless ICMPv4/ICMPv6 Ping library for NodeJS

Downloads

29

Readme

Ping library for NodeJS

Does it work?

it seems to...

Does it require root?

nope!

This library simply pings a host, and tracks the latency over time.

Simply construct a Pinger with a host name / address and start() it!

const pinger = await createPinger(`${addr}`)

pinger.start()

// wait for some time... then collect stats
const stats = pinger.stats()

// `stats` will now contain
// {
//   sent: 123,     // the number of ECHO Requests sent since the last call to `stats()`
//   received: 120, // the number of ECHO Responses received since the last call to `stats()`
//   latency: 98,   // the average PING latency since the last call to `stats()`
// }

ping.close()

Creating a Pinger

A Pinger instance can be created calling the asynchronous createPinger(...) method. This method takes two parameters:

  • to: an IPv4 or IPv6 IP address to ping, or a host name. By default host names will be resolved as IPv4 (A records), unless the options.protocol value is set to ipv6, in which case it will be resolved as an IPv6 (AAAA record).
  • options: an optional object containing options for the Pinger.

Options

  • protocol: (either ipv4 or ipv6) the protocol to use. if the to address is an IPv6 address the protocol will default to ipv6, in all other cases it will default to ipv4.
  • from: the IP address ping from; this is useful when
  • source: the interface name used as the source of our ICMP packages.
  • timeout: (default: 30000 or 30 seconds) the timeout in milliseconds after which a packet is considered lost.
  • interval: (default: 1000 or 1 second) the interval in milliseconds used to ping the remote host.

The Pinger interface

Methods

  • ping(): that's it... send an ICMP Echo Request packet.
  • start(): starts the Pinger, collecting stats and emitting events.
  • stop(): stops the Pinger, but keeps the underlying socket open.
  • close(): stops the Pinger and closes the underlying socket.
  • stats(): collect and reset statistics.

Properties

  • target: the target IP address to ping to.
  • from: the source IP address used to ping from or undefined.
  • source: the name of the source interface being used or undefined.
  • timeout: the timeout in milliseconds after which a packet is considered lost.
  • interval: the iterval in milliseconds at which ECHO requests are sent.
  • protocol: the IP protocol, either ipv4 or ipv6.
  • running: whether the Pinger is running or not.
  • closed: whether the socket is closed or not.

Events

  • pong(latency): when an ECHO Reply packet is received (latency is in milliseconds).
  • warning(code, message): when a warning occurred it includes an error code and relative message.
  • error: when an error occurred; in this case the pinger is automatically closed.

Command Line

A brain dead command line interface is also available (useful for debugging):

$ juit-ping -I lo0 127.0.0.1

Parameters

  • -4: Force the use of IPv4/ICMPv4.
  • -6: Force the use of IPv6/ICMPv6.
  • -I address|interface: Address or interface name to use for pinging from