Code Monkey home page Code Monkey logo

routeros-node's Introduction

Routeros Node

Routeros Node allows users to create custom software solutions to communicate with RouterOS to gather information, adjust configuration and manage router. API closely follows syntax from command line interface (CLI). It can be used to create translated or custom configuration tools to aid ease of use running and managing routers with RouterOS.

To use API RouterOS version 3.x or newer is required. By default API uses port 8728 and service is enabled.

This library requires Routeros version v6.43 and above.

Installation

npm install routeros-node

Making Connection

const { Routeros } = require("routeros-node");

async function run() {
  const routeros = new Routeros({
    host: "127.0.0.1",
    port: 8728,
    user: "admin",
    password: "",
  });

  try {
    // connect to RouterOS
    const conn = await routeros.connect();

    // if connected successfully will return the connected instance/socket,
    console.log("conn===>", conn);

    // after that we can write the query
    const usersHotspot = conn.write(["/ip/hotspot/user/print"]);
    console.log(usersHotspot);
  } catch (error) {
    // if it fails will return an error here
    console.log("error===>", error);
  } finally {
    // dont forget to close connection
    routeros.destroy();
  }
}

run();

We can also use promises:

const { Routeros } = require("routeros-node");

const routeros = new Routeros({
  host: "127.0.0.1",
  port: 8728,
  user: "admin",
  password: "",
});

routeros
  .connect()
  .then((conn) => conn.write(["/ip/hotspot/user/print"]))
  .then((usersHotspot) => {
    console.log(usersHotspot);
  })
  .catch((error) => {
    console.log("error===>", error);
  })
  .finnaly(() => {
    routeros.destroy();
  });

Performing a query

Method write() receives an array, we can put all RouterOS query words into that array. See: https://wiki.mikrotik.com/wiki/Manual:API#Query_word

For example, create a new hotspot user with the name test: write(['/ip/hotspot/user/add', '=name=test']).

routeros-node's People

Contributors

kilisio avatar renomureza avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.