Trebejo.Network (Trebejo v2.0.0)

Copy Markdown View Source

Network operations: TCP port checks and ICMP ping.

TCP operations (port_open?/3, scan_ports/3) use :gen_tcp directly. ICMP ping uses Trebejo.Util.run_cmd/3 with arg lists — never interpolated into shell strings — to prevent shell injection. For DNS resolution use Apero.Network.resolve/1 directly.

Summary

Functions

Sends ICMP ping to a host.

Checks if a TCP port is open on a host.

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)

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.