Skip to content
Orion edited this page Nov 27, 2024 · 1 revision

The core module provided a basic tools to handle IP and Mac addresses validation, defining a networks, getting local network interfaces information and more.

Contents

IpVersion

Global that present the two IP version

used to check if a giving string address is a valid Ipv4 or Ipv6 address

Members

  • V4
  • V6

Functions

  • is_v4

    • Description: checks if a giving address is a valid Ipv4 address
    • Arguments: address - string
    • Returns: boolean , true if valid Ipv4, false otherwise
  • is_v6 -

    • Description: checks if a giving address is a valid Ipv6 address
    • Arguments: address - string
    • Returns: boolean , true if valid Ipv6, false otherwise

IpKind

Global that present the varies kinds of IP address.

used to check if a giving address is from specific kind of address or get the type of the address.

Members

  • Public
  • Private
  • Loopback
  • LinkLocal
  • Apipa
  • UniqeLocal
  • UniqeGlobal
  • Broadcast
  • Netid
  • Multicast
  • Unspecified

Functions

  • is_public

    • Description: checks if a giving address is a public Ipv4 address

    • Arguments: address - string

    • Returns: boolean, true if public, false otherwise

  • is_private

    • Description: checks if a giving address is a private Ipv4 address

    • Arguments: address - string

    • Returns: boolean, true if private, false otherwise

  • is_loopback

    • Description: checks if a giving address is a loopback Ipv4 address

    • Arguments: address - string

    • Returns: boolean, true if loopback, false otherwise

  • is_linklocal

    • Description: checks if a giving address is a linklocal Ipv6 address

    • Arguments: address - string

    • Returns: boolean, true if linklocal, false otherwise

  • is_apipa

    • Description: checks if a giving address is an apipa Ipv4 address

    • Arguments: address - string

    • Returns: boolean, true if apipa, false otherwise

  • is_multicast

    • Description: checks if a giving address is a multicast address

    • Arguments: address - string

    • Returns: boolean, true if multicast, false otherwise

  • is_unspecified

    • Description: checks if a giving address is a unspecified address

    • Arguments: address - string

    • Returns: boolean, true if unspecified, false otherwise

  • is_broadcast

    • Description: checks if a giving address is a broadcast address

    • Arguments:

      • address - string,
      • mask - Mask
    • Returns: boolean, true if is valid broadcast address in the mask range, false otherwise

  • is_netid

    • Description: checks if a giving address is a net id

    • Arguments:

      • address - string,
      • mask - Mask
    • Returns: boolean, true if is a net id in the mask range, false otherwise

  • get_kind

    • Description: gets the type of a giving address if valid

    • Arguments: address - string

    • Returns: IpKind member if valid address otherwise BadArgument error would be raised

  • get_broadcast

    • Description: gets broadcast by a giving net id and a mask

    • Arguments:

      • address - string,
      • mask - Mask
    • Returns: IpAddress if valid net id otherwise BadArgument error would be raised

IpAddress

Global that present an IP address userdata.

Properties

  • address - string
  • version - IpVersion
  • kind - IpKind

Methods

  • get_octets

    • Description: get the octets of the address

    • Arguments: self

    • Returns: table

  • get_expended

    • Description: expends a giving Ipv6 address

    • Arguments: self

    • Returns: string

Functions

  • new

    • Description: creates a new IpAddress instance

    • Arguments: address - string

    • Returns: IpAddress if valid address otherwise BadArgument error would be raised

  • is_valid

    • Description: checks if a giving address is a valid IP address

    • Arguments: address - string

    • Returns: boolean, true if valid, false otherwise

  • expend

    • Description: expends a giving Ipv6 address

    • Arguments: address - string

    • Returns: string if valid address otherwise BadArgument error would be raised

  • shorten

    • Description: shorten a giving Ipv6 address

    • Arguments: address - string

    • Returns: string if valid address otherwise BadArgument error would be raised

  • eui64

    • Description: creates a linklocal address from a giving mac using the eui64 algorithm

    • Arguments: mac - MacAddress

    • Returns: IpAddress

Mask

Global that present a network mask userdata.

Properties

  • mask - string
  • prefix - number
  • num_of_hosts - number

Functions

  • new

    • Description: creates a new Mask instance

    • Arguments: mask - string

    • Returns: Mask if valid mask otherwise BadArgument error would be raised

  • is_valid

    • Description: checks if a giving mask is a valid network mask

    • Arguments: mask - string

    • Returns: boolean, true if valid, false otherwise

  • from_prefix

    • Description: creates a new Mask instance from a giving mask prefix

    • Arguments: prefix - number

    • Returns: Mask if valid prefix otherwise BadArgument error would be raised

  • get_prefix

    • Description: gets the mask prefix from a giving mask

    • Arguments: mask - string

    • Returns: number if valid mask otherwise BadArgument error would be raised

Network

Global that present a IP network userdata.

Properties

  • broadcast - IpAddress
  • netid - IpAddress
  • mask - Mask

Methods

  • contains

    • Description: check if a giving IpAddress is part of the network

    • Arguments:

      • self
      • address - IpAddress
    • Returns: boolean, true if is part of the network false otherwise

  • contains_str

    • Description: expends a giving Ipv6 address

    • Arguments:

      • self
      • address - string
    • Returns: boolean, true if is part of the network false otherwise

Functions

  • new

    • Description: creates a new Network instance

    • Arguments:

      • netid - IpAddress
      • mask - Mask
    • Returns: Network if valid net id with the mask range otherwise BadArgument error would be raised

  • from

    • Description: creates a new Network instance from string {net_id}/{prefix} format

    • Arguments: net - string

    • Returns: Network if valid net id with the prefix range and in the {net_id}/{prefix} format otherwise BadArgument error would be raised

MacAddress

Global that present a mac address userdata.

Properties

  • address - string

Methods

  • as_array

    • Description: get the parts of the mac address

    • Arguments: self

    • Returns: table

  • as_bytes

    • Description: get the parts of the mac address as bytes

    • Arguments: self

    • Returns: table

Functions

  • new

    • Description: creates a new MacAddress instance

    • Arguments: mac - string

    • Returns: MacAddress if valid mac otherwise BadArgument error would be raised

  • is_valid

    • Description: checks if a giving mac address is a valid

    • Arguments: mac - string

    • Returns: boolean, true if valid, false otherwise

Operators

  • ==, >, >=, <, <=

can be used to compare between to giving MacAddresss

Interface

Properties

  • name - string
  • index - number
  • description - string
  • mac - MacAddress
  • ipv4 - IpAddress
  • ipv6 - IpAddress
  • mask - Mask

Functions

  • by_index

    • Description: creates a new Interface instance as the local machine network interface with the giving index

    • Arguments: index - number

    • Returns: Interface if valid index otherwise BadArgument error would be raised

  • by_name

    • Description: creates a new Interface instance as the local machine network interface with the giving name

    • Arguments: name - string

    • Returns: Interface if valid name otherwise BadArgument error would be raised

  • all

    • Description: gets a Interface instances array as all the local machine network interfaces

    • Returns: Table