HSNetworkPing
TypeObject 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.
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.
Methods
packets(sequenceNumber) -> any
Returns packet statistics for all sent packets, or for a single packet by its zero-based sequence number.
Declaration
packets(sequenceNumber) -> any
Parameters
| 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. |
Returns
any
An array of packet objects when called without arguments, or a single packet object (or `null`).
Example
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.
Declaration
summary() -> string
Returns
string
A multi-line string with transmission statistics and round-trip timing.
Example
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.
Declaration
pause() -> HSNetworkPing
Returns
HSNetworkPing
This ping object if still active, or `null` if the ping has already finished.
Example
const p = hs.network.ping("example.com")
setTimeout(() => p.pause(), 2000)
resume() -> HSNetworkPing
Resumes a paused ping, continuing from where it left off.
Declaration
resume() -> HSNetworkPing
Returns
HSNetworkPing
This ping object if still active, or `null` if the ping has already finished.
Example
p.pause()
setTimeout(() => p.resume(), 5000)
cancel() -> None
Immediately stops the ping, firing the `"didFinish"` callback with statistics collected so far.
Declaration
cancel() -> None
Returns
None
Example
const p = hs.network.ping("example.com", { count: 100 })
setTimeout(() => p.cancel(), 3000)
setCallback(callback) -> HSNetworkPing
Replaces the ping's callback function.
Declaration
setCallback(callback) -> HSNetworkPing
Parameters
| Name | Type | Description |
|---|---|---|
| callback | function | The new callback function. |
Returns
HSNetworkPing
This ping object for chaining.
Example
const p = hs.network.ping("example.com")
p.setCallback((ping, event, info) => {
if (event === "receivedPacket") {
console.log("RTT: " + (info.rtt * 1000).toFixed(1) + " ms")
}
})