Lunatik

netModule

Network utility functions.

This module provides helper functions for network-related operations, primarily for converting between string and integer representations of IPv4 addresses.

Functions

aton (addr) Converts an IPv4 address string to its integer representation.
ntoa (ip) Converts an integer representation of an IPv4 address to its string form.

Functions in detail

aton (addr)
Converts an IPv4 address string to its integer representation. “Address to Number”

Parameters

  • addr (string) The IPv4 address string, four decimal octets from 0 to 255 joined by dots, with no leading zero (e.g., “127.0.0.1”).

Returns

    (number) The IPv4 address as an integer.

Raises

“invalid IPv4 address” for any other string.

Usage

local ip_int = net.aton("192.168.1.1")
ntoa (ip)
Converts an integer representation of an IPv4 address to its string form. “Number to Address”

Parameters

  • ip (number) The IPv4 address as an integer.

Returns

    (string) The IPv4 address string (e.g., “127.0.0.1”).

Usage

local ip_str = net.ntoa(3232235777)  -- "192.168.1.1"