HSNetworkPing
TypeObject representing an active or completed ICMP ping operation.
Create instances with hs.network.ping().
Properties
address
The resolved IP address of the target, or "<unresolved address>" if DNS has not yet completed.
count
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.
Each packet object contains:
sequenceNumber(number) — zero-based indexicmpIdentifier(number) — the ICMP identifier used (may be kernel-assigned)status(string) —"sent","received", or"timeout"rtt(number | null) — round-trip time in seconds, ornullif 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. |
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
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
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
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
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. |
const p = hs.network.ping("example.com")
p.setCallback((ping, event, info) => {
if (event === "receivedPacket") {
console.log("RTT: " + (info.rtt * 1000).toFixed(1) + " ms")
}
})