API Docs

Object representing an active or completed ICMP ping operation. Create instances with hs.network.ping().

Properties

address

string

The resolved IP address of the target, or "<unresolved address>" if DNS has not yet completed.

server

string

The hostname or IP address string originally passed to hs.network.ping().

sent

number

The number of ICMP Echo Requests sent so far.

count

number

The total number of ICMP Echo Requests to send. May be increased while the ping is running provided the new value is greater than the number already sent.

isRunning

boolean

true while the ping is actively sending and waiting for replies.

isPaused

boolean

true when the ping has been suspended with pause().

Methods

packets(sequenceNumber) -> any

Returns packet statistics for all sent packets, or for a single packet by its zero-based sequence number.

Each packet object contains:

  • sequenceNumber (number) — zero-based index
  • icmpIdentifier (number) — the ICMP identifier used (may be kernel-assigned)
  • status (string) — "sent", "received", or "timeout"
  • rtt (number | null) — round-trip time in seconds, or null if no reply was received
packets(sequenceNumber) -> any
Name Type Description
sequenceNumber JSValue Omit to get all packets as an array; pass an integer to get a single packet object, or null if that sequence does not exist.
any
An array of packet objects when called without arguments, or a single packet object (or null).
const p = hs.network.ping("example.com", {
  callback: (ping, event) => {
    if (event === "didFinish") console.log(ping.packets())
  }
})

summary() -> string

Returns a human-readable summary of the ping results in standard ping format.

summary() -> string
string
A multi-line string with transmission statistics and round-trip timing.
const p = hs.network.ping("example.com", {
  callback: (ping, event) => {
    if (event === "didFinish") console.log(ping.summary())
  }
})

pause() -> HSNetworkPing

Suspends the ping. No further packets are sent until resume() is called.

pause() -> HSNetworkPing
HSNetworkPing
This ping object if still active, or null if the ping has already finished.
const p = hs.network.ping("example.com")
setTimeout(() => p.pause(), 2000)

resume() -> HSNetworkPing

Resumes a paused ping, continuing from where it left off.

resume() -> HSNetworkPing
HSNetworkPing
This ping object if still active, or null if the ping has already finished.
p.pause()
setTimeout(() => p.resume(), 5000)

cancel() -> None

Immediately stops the ping, firing the "didFinish" callback with statistics collected so far.

cancel() -> None
None
const p = hs.network.ping("example.com", { count: 100 })
setTimeout(() => p.cancel(), 3000)

setCallback(callback) -> HSNetworkPing

Replaces the ping's callback function.

The callback receives (ping, event, info):

  • "didStart" — info is the resolved IP address string.
  • "didFail" — info is an error message string.
  • "sendPacketFailed" — info is [packetObject, errorString].
  • "receivedPacket" — info is the packet object.
  • "didFinish" — info is the summary string.
setCallback(callback) -> HSNetworkPing
Name Type Description
callback function The new callback function.
HSNetworkPing
This ping object for chaining.
const p = hs.network.ping("example.com")
p.setCallback((ping, event, info) => {
  if (event === "receivedPacket") {
    console.log("RTT: " + (info.rtt * 1000).toFixed(1) + " ms")
  }
})