hammerspoon2-docs
    Preparing search index...

    Function ping

    • Sends ICMP Echo Requests to server and reports results via a callback.

      DNS resolution and the first ping begin immediately. The returned object can be used to pause, resume, or cancel the ping, and to read statistics. The ping runs to completion, with its callback, even if you don't keep a reference to it.

      The options argument may be:

      • Omitted (or undefined) — uses all defaults.
      • A callback function — used as the event handler with all other options at their defaults.
      • An object with any of: count (integer, default 5), interval (seconds, default 1.0), timeout (seconds per packet, default 2.0), family ("any" | "ipv4" | "ipv6", default "any"), and callback (function).

      The callback receives (ping, event, info):

      • "didStart" — info is the resolved IP address string.
      • "didFail" — info is an error message string (e.g. DNS failure).
      • "sendPacketFailed" — info is [packetObject, errorString].
      • "receivedPacket" — info is the packet object (see HSNetworkPing.packets()).
      • "didFinish" — info is the summary string.

      Parameters

      • server: string

        A hostname or IP address to ping.

      • Optionaloptions:
            | {
                callback?: (ping: HSNetworkPing, event: string, info: any) => void;
                count?: number;
                family?: string;
                interval?: number;
                timeout?: number;
            }
            | ((ping: HSNetworkPing, event: string, info: any) => void)

        A callback function or options object. Optional.

      Returns HSNetworkPing | null

      An HSNetworkPing object, or null if the arguments are invalid.