Module eco.net

Network utilities.

Currently this module provides simple ICMP echo (ping) helpers for both IPv4 and IPv6.

Functions

ping (host[, opts]) Send an ICMP echo request (IPv4).
ping6 (host[, opts]) Send an ICMP echo request (IPv6).

Tables

PingOptions Options table for net.ping / net.ping6.


Functions

ping (host[, opts])
Send an ICMP echo request (IPv4).

If host is a domain name, it will be resolved using DNS A records.

Parameters:

  • host string IPv4 address or domain name.
  • opts PingOptions Options table. (optional)

Returns:

    number Round-trip time in seconds.

Or

  1. nil On failure.
  2. string err Error message.

Usage:

    local net = require 'eco.net'
    local rtt, err = net.ping('8.8.8.8', { timeout = 1 })
    print(rtt or err)
ping6 (host[, opts])
Send an ICMP echo request (IPv6).

If host is a domain name, it will be resolved using DNS AAAA records.

Parameters:

  • host string IPv6 address or domain name.
  • opts PingOptions Options table. (optional)

Returns:

    number Round-trip time in seconds.

Or

  1. nil On failure.
  2. string err Error message.

Tables

PingOptions
Options table for net.ping / net.ping6.

Fields:

  • timeout number Receive timeout in seconds. (default 5.0)
  • data string ICMP payload. (default "hello")
  • mark number Set SO_MARK on the underlying socket (Linux). (optional)
  • device string Bind socket to a specific interface (e.g. "eth0"). (optional)
  • nameservers table DNS servers used for name resolution. Each entry is typically an IP string (e.g. { "1.1.1.1", "8.8.8.8" }). (optional)
generated by LDoc 1.5.0 Last updated 2026-04-09 14:48:22