Skip to content

IP

Ip

Bases: Base

Class that generates the connection with a MikroTik router.

Attributes:

Name Type Description
service dict

Dictionary with the services available on the router.

Source code in netmikro/modules/ip.py
class Ip(Base):
    """Class that generates the connection with a MikroTik router.

    Attributes:
        service (dict): Dictionary with the services available on the router.
    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        _service_names = [
            'api',
            'api-ssl',
            'ftp',
            'ssh',
            'telnet',
            'winbox',
            'www',
            'www-ssl',
        ]

        self.service = {
            service: IpService(
                port=int(self._get(f'/ip service get {service} port')),
                disabled=self._get_bool(f'/ip service get {service} disabled'),
                available_from=self._get(f'/ip service get {service} address'),
            )
            for service in _service_names
        }

    def ip_port_set(self, service_name: str, port: int) -> None:
        """Set the API port number.

        Args:
            service_name: The service to be changed.
            port: The new port number.

        Examples:
            >>> router.ip_port_set('www', 8080)
        """
        self._cmd(
            f'/ip service set {service_name} port={Port(port=port).port}'
        )
        self.service[service_name].port = port

ip_port_set(service_name, port)

Set the API port number.

Parameters:

Name Type Description Default
service_name str

The service to be changed.

required
port int

The new port number.

required

Examples:

>>> router.ip_port_set('www', 8080)
Source code in netmikro/modules/ip.py
def ip_port_set(self, service_name: str, port: int) -> None:
    """Set the API port number.

    Args:
        service_name: The service to be changed.
        port: The new port number.

    Examples:
        >>> router.ip_port_set('www', 8080)
    """
    self._cmd(
        f'/ip service set {service_name} port={Port(port=port).port}'
    )
    self.service[service_name].port = port

IpService

Class for representing ip service on a MikroTik router.

Attributes:

Name Type Description
port int

Port number of the service.

disabled bool

Whether the service is disabled or not.

available_from str

IP address from which the service is available.

Examples:

>>> service = IpService(8728, False, '192.168.88.1')
Source code in netmikro/modules/ip.py
@dataclass
class IpService:
    """Class for representing ip service on a MikroTik router.

    Attributes:
        port (int): Port number of the service.
        disabled (bool): Whether the service is disabled or not.
        available_from (str): IP address from which the service is available.

    Examples:
        >>> service = IpService(8728, False, '192.168.88.1')
    """

    port: int
    disabled: bool
    available_from: str