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
hostis 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
- nil On failure.
- 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
hostis 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
- nil On failure.
- 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_MARKon 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)