All Projects → aluisiora → node-routeros

aluisiora / node-routeros

Licence: MIT license
Mikrotik Routerboard RouterOS API for NodeJS

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-routeros

routeros-client
Abstraction layer over the node-routeros API
Stars: ✭ 63 (-27.59%)
Mutual labels:  mikrotik, routeros, routerboard, routeros-node
RouterOS Useful Scripts
MikroTik RouterOS Useful Scripts for various use
Stars: ✭ 66 (-24.14%)
Mutual labels:  mikrotik, routeros, routerboard
Easy-HotSpot
Easy HotSpot is a super easy WiFi hotspot user management utility for Mikrotik RouterOS based Router devices. Voucher printing in 6 ready made templates are available. Can be installed in any PHP/MySql enabled servers locally or in Internet web servers. Uses the PHP PEAR2 API Client by boenrobot.
Stars: ✭ 45 (-48.28%)
Mutual labels:  mikrotik, routeros
mbkp
Mikrotik backup script | simple bash script for doing encrypted backups of mikrotik devices(Routeros) via ssh. Script will do password-protected binary and encrypted with openssl export on regular basis
Stars: ✭ 21 (-75.86%)
Mutual labels:  mikrotik, routeros
npk-tools
Mikrotik's NPK files managing tools
Stars: ✭ 63 (-27.59%)
Mutual labels:  mikrotik, routeros
ROS Scripts
Scripts for RouterOS (MikroTik devices)
Stars: ✭ 81 (-6.9%)
Mutual labels:  mikrotik, routeros
docker-routeros
Mikrotik RouterOS inside Docker container
Stars: ✭ 225 (+158.62%)
Mutual labels:  mikrotik, routeros
chr-eve-ng
Repository contain LAB's for Mikrotik trainings and helpers for installing CHR into eve-ng.
Stars: ✭ 28 (-67.82%)
Mutual labels:  mikrotik, routeros
docker-dude
The Dude (MikroTik) server in a container
Stars: ✭ 48 (-44.83%)
Mutual labels:  mikrotik
Fastnetmon
FastNetMon - very fast DDoS sensor with sFlow/Netflow/IPFIX/SPAN support
Stars: ✭ 2,860 (+3187.36%)
Mutual labels:  mikrotik
perfectrestore
MikroTik config restore helper script
Stars: ✭ 53 (-39.08%)
Mutual labels:  mikrotik
Chimay-Red-tiny
This is a minified exploit for mikrotik routers. It does not require any aditional modules to run.
Stars: ✭ 25 (-71.26%)
Mutual labels:  mikrotik
Mikrotik API
Mikrotik Dashboard
Stars: ✭ 46 (-47.13%)
Mutual labels:  mikrotik
mikrotik-json-parser
JSON parser library for RouterOS
Stars: ✭ 41 (-52.87%)
Mutual labels:  mikrotik
phpmixbill
PHP Mikrotik Billing - Voucher management for Mikrotik Hotspot
Stars: ✭ 134 (+54.02%)
Mutual labels:  mikrotik
Mikrotik-Blacklist
Mikrotik friendly blacklist to filter all these damn hackers.
Stars: ✭ 70 (-19.54%)
Mutual labels:  mikrotik
aws-vpn-mikrotik
Shell script to transform a Generic AWS VPN configuration guide to MikroTik specific set up commands that can be copy pasted into a mikrotik console to set up the customer end of the connection.
Stars: ✭ 38 (-56.32%)
Mutual labels:  mikrotik
telegram bot
Script ini digunakan untuk mengontrol MikroTik Anda hanya dengan menggunakan sosial media Telegram.
Stars: ✭ 27 (-68.97%)
Mutual labels:  mikrotik
topolograph
Topolograph.com is an online project which can visualize OSPF/ISIS topology based on single OSPF LinkState DataBase scrapping from one network device ( thanks OSPF =). Then you can not only see (and check) the shortest path from source to destination, but also see the outcome from link or node failure along the path to the destination. The exist…
Stars: ✭ 84 (-3.45%)
Mutual labels:  mikrotik
mikrotik-fwban
Use your Mikrotik firewall to do fail2ban like blocking of unwanted IPs. Written in Go
Stars: ✭ 22 (-74.71%)
Mutual labels:  mikrotik

Discontinued

I worked on this project in my spare time, but unfortunately I no longer work with mikrotik devices and don't have the free time anymore, so consider it as discontinued. Feel free to fork this project and create your own spin.

Description

This is a Mikrotik Routerboard API written in Typescript for nodejs, can be either used with plain javascript or imported on typescript projects.

This library will handle the API in a more lowerlevel way, for a simpler to use interface I recommend my routeros-client for a more "object-oriented" API, which wraps this API. It has a very rich documentation, so please check it out.

Features

  • Connection and reconnection without destroying the object.
  • Change host, username and other parameters of the object without recreating it.
  • Based on promises.
  • You can choose to keep the connection alive if it gets idle.
  • Every command is async, but can be synced using the promises features.
  • Can pause, resume and stop streams (like what you get from /tool/torch).
  • Support languages with accents, keeping it consistent throughout winbox and api.

Installing

npm install node-routeros --save

Documentation

Check the wiki for a complete documentation.

Examples

You can import in TypeScript using:

import { RouterOSAPI } from 'node-routeros';

Adding an IP address to ether2, printing it, then removing it synchronously:

const RosApi = require('node-routeros').RouterOSAPI;

const conn = new RosApi({
    host: '192.168.88.1',
    user: 'admin',
    password: '',
});

conn.connect()
    .then(() => {
        // Connection successful

        // Let's add an IP address to ether2
        conn.write('/ip/address/add', [
            '=interface=ether2',
            '=address=192.168.90.1',
        ])
            .then((data) => {
                console.log('192.168.90.1 added to ether2!', data);

                // Added the ip address, let's print it
                return conn.write('/ip/address/print', ['?.id=' + data[0].ret]);
            })
            .then((data) => {
                console.log('Printing address info: ', data);

                // We got the address added, let's clean it up
                return conn.write('/ip/address/remove', [
                    '=.id=' + data[0]['.id'],
                ]);
            })
            .then((data) => {
                console.log('192.168.90.1 as removed from ether2!', data);

                // The address was removed! We are done, let's close the connection
                conn.close();
            })
            .catch((err) => {
                // Oops, got an error
                console.log(err);
            });
    })
    .catch((err) => {
        // Got an error while trying to connect
        console.log(err);
    });

Listening data from /ip/torch and using pause/resume/stop feature:

const RosApi = require("node-routeros").RouterOSAPI;

const conn = new RosApi({
    host: "192.168.88.1",
    user: "admin"
    password: ""
});

conn.connect().then(() => {
    // Counter to trigger pause/resume/stop
    let i = 0;

    // The stream function returns a Stream object which can be used to pause/resume/stop the stream
    const addressStream = conn.stream(['/tool/torch', '=interface=ether1'], (error, packet) => {
        // If there is any error, the stream stops immediately
        if (!error) {
            console.log(packet);

            // Increment the counter
            i++;

            // if the counter hits 30, we stop the stream
            if (i === 30) {

                // Stopping the stream will return a promise
                addressStream.stop().then(() => {
                    console.log('should stop');
                    // Once stopped, you can't start it again
                    conn.close();
                }).catch((err) => {
                    console.log(err);
                });

            } else if (i % 5 === 0) {

                // If the counter is multiple of 5, we will pause it
                addressStream.pause().then(() => {
                    console.log('should be paused');

                    // And after it is paused, we resume after 3 seconds
                    setTimeout(() => {
                        addressStream.resume().then(() => {
                            console.log('should resume');
                        }).catch((err) => {
                            console.log(err);
                        });
                    }, 3000);

                }).catch((err) => {
                    console.log(err);
                });

            }

        }else{
            console.log(error);
        }
    });

}).catch((err) => {
    // Got an error while trying to connect
    console.log(err);
});

Cloning this repo

Note that, if are cloning this repo, you must be familiar with Typescript so you can make your changes.

Testing

In order to run the tests, I used RouterOS CHR on a virtual machine with 4 interfaces, where the first interface is a bridge of my network card:

VirtualBox RouterOS CHR Conf

TODO

  • Write more tests

Credits

This project is entirely based on George Joseph and Brandon Myers's work with mikronode, thank you very much!!!

License

MIT License

Copyright (c) 2017 Aluísio Rodrigues Amaral

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].