New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mikro-client

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mikro-client

Simple library using socket API to connect and control Mikrotik devices in JavaScript or TypeScript. Allows for easy automation of Mikrotik device management and configuration tasks.

latest
Source
npmnpm
Version
0.5.3
Version published
Weekly downloads
78
73.33%
Maintainers
1
Weekly downloads
 
Created
Source

mikro-client

This library, written in TypeScript and also compatible with JavaScript, provides a simple connection via TCP sockets to send and receive command-line commands from MikroTik. With this library, you can easily and quickly control and get information from a MikroTik device.

version documentation in:

  • English
  • Spanish

Installation

npm install mikro-client

or

yarn add mikro-client

Usage

To use the class, you must first import it into your project:

import { MikroClient } from 'mikro-client'

Then, you can create a new instance of the class by providing the necessary configuration options:

const options = {
  host: 'XXX.XXX.XXX.XXX',
  port: XXXX,
  username: 'xxxxx',
  password: 'xxxxx',
  timeout: 5000,
}
const mikro = new MikroClient(options)

Once you have an instance of the class, you can use the "talk" method to send MikroTik commands to the device and receive the response:

const response = await mikro
  .talk(['/interface/print'])
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.error(error)
  })

You can also specify the type of response you want to receive using the optional "type" argument:

const response = await mikro
  .talk(['/interface/print'], 'object')
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.error(error)
  })

Examples

Here are some examples of MikroTik commands that you can send using the "talk" method:

  • Get network interface information:
const response = await mikro
  .talk(['/interface/print'])
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.error(error)
  })
  • Add a firewall rule:
mikro
  .talk([
    '/ip/firewall/filter/add',
    '=chain=forward',
    '=protocol=tcp',
    '=dst-port=80',
    '=action=accept',
  ])
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.error(error)
  })
  • Get connected user information:
mikro
  .talk(['/ip/hotspot/active/print'])
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.error(error)
  })
  • Create a hotspot user:
mikro
  .talk([
    '/ip/hotspot/user/add',
    '=name=example',
    '=password=example',
    '=profile=default',
  ])
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.error(error)
  })

Information

For more information on the MikroTik commands that you can send using the MikroApi class, we recommend consulting the MikroTik documentation, which is available at the following link:

On this page, you will find a complete list of available MikroTik commands and their respective parameters. You will also find examples of how to use these commands in the MikroTik command line and API.

I hope this helps you get more information on MikroTik commands and how to use them with the MikroApi class. If you have any additional questions, don't hesitate to ask.

License

Created by jjjjose - 2022

Keywords

mikrotik

FAQs

Package last updated on 25 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts