Trebejo.Network (Trebejo v1.0.0)

Copy Markdown View Source

Network operations: ping, DNS, TCP port checks.

Summary

Functions

Sends ICMP ping to a host.

Checks if a TCP port is open on a host.

Resolves a hostname to a list of IP addresses.

Scans a list of TCP ports on a host.

Types

tcp_port()

@type tcp_port() :: 0..65535

Functions

ping(host, opts \\ [])

@spec ping(
  String.t(),
  keyword()
) :: :ok | {:error, term()}

Sends ICMP ping to a host.

Returns :ok on success or {:error, reason} on failure.

Options

  • :count — number of echo requests (default: 3)
  • :timeout — timeout in ms (default: 5_000)

port_open?(host, port, opts \\ [])

@spec port_open?(String.t(), tcp_port(), keyword()) :: boolean()

Checks if a TCP port is open on a host.

Options

  • :timeout — connection timeout in ms (default: 5_000)

resolve(host)

@spec resolve(String.t()) :: {:ok, [String.t()]} | {:error, atom()}

Resolves a hostname to a list of IP addresses.

Returns {:ok, [String.t()]} or {:error, :nxdomain} on failure.

scan_ports(host, ports, opts \\ [])

@spec scan_ports(String.t(), [tcp_port()], keyword()) :: %{
  required(tcp_port()) => :open | :closed
}

Scans a list of TCP ports on a host.

Returns a map of port → :open | :closed.